From 0aed816eba20ad7bfae05556d57d0fb3c3030226 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Nov 2022 16:33:44 +0100 Subject: [PATCH] Suppress nullable warnings in Serialization.Schema Now that Schema compiles against the source assembly of System.CodeDom, it receives nullability errors. I'm suppressing them manually for now but am filing an issue to correctly fix those. Related: https://github.com/dotnet/runtime/issues/78036 --- .../Runtime/Serialization/Schema/CodeExporter.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Runtime.Serialization.Schema/src/System/Runtime/Serialization/Schema/CodeExporter.cs b/src/libraries/System.Runtime.Serialization.Schema/src/System/Runtime/Serialization/Schema/CodeExporter.cs index e0282ac4d556b..57064b5d1b003 100644 --- a/src/libraries/System.Runtime.Serialization.Schema/src/System/Runtime/Serialization/Schema/CodeExporter.cs +++ b/src/libraries/System.Runtime.Serialization.Schema/src/System/Runtime/Serialization/Schema/CodeExporter.cs @@ -518,8 +518,8 @@ private static CodeTypeDeclaration CreateTypeDeclaration(string typeName, DataCo CodeAttributeDeclaration generatedCodeAttribute = new CodeAttributeDeclaration(typeof(GeneratedCodeAttribute).FullName!); AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName(); - generatedCodeAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(assemblyName.Name))); - generatedCodeAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(assemblyName.Version?.ToString()))); + generatedCodeAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(assemblyName.Name!))); + generatedCodeAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(assemblyName.Version?.ToString()!))); // System.Diagnostics.DebuggerStepThroughAttribute not allowed on enums // ensure that the attribute is only generated on types that are not enums @@ -818,7 +818,7 @@ private void ExportClassDataContract(DataContract classDataContract, ContractCod { ContractCodeDomInfo baseContractCodeDomInfo = GetContractCodeDomInfo(classDataContract.BaseContract); Debug.Assert(baseContractCodeDomInfo.IsProcessed, "Cannot generate code for type if code for base type has not been generated"); - type.BaseTypes.Add(baseContractCodeDomInfo.TypeReference); + type.BaseTypes.Add(baseContractCodeDomInfo.TypeReference!); AddBaseMemberNames(baseContractCodeDomInfo, contractCodeDomInfo); if (baseContractCodeDomInfo.ReferencedTypeExists) { @@ -1151,7 +1151,7 @@ private void ExportISerializableDataContract(DataContract classDataContract, Con { ContractCodeDomInfo baseContractCodeDomInfo = GetContractCodeDomInfo(classDataContract.BaseContract); GenerateType(classDataContract.BaseContract, baseContractCodeDomInfo); - type.BaseTypes.Add(baseContractCodeDomInfo.TypeReference); + type.BaseTypes.Add(baseContractCodeDomInfo.TypeReference!); if (baseContractCodeDomInfo.ReferencedTypeExists) { Type? actualType = (Type?)baseContractCodeDomInfo.TypeReference?.UserData[s_codeUserDataActualTypeKey]; @@ -1236,7 +1236,7 @@ private void ExportCollectionDataContract(DataContract collectionContract, Contr Debug.Assert(contractCodeDomInfo.TypeDeclaration != null); CodeTypeDeclaration generatedType = contractCodeDomInfo.TypeDeclaration; - generatedType.BaseTypes.Add(baseTypeReference); + generatedType.BaseTypes.Add(baseTypeReference!); CodeAttributeDeclaration collectionContractAttribute = new CodeAttributeDeclaration(GetClrTypeFullName(typeof(CollectionDataContractAttribute))); collectionContractAttribute.Arguments.Add(new CodeAttributeArgument(ImportGlobals.NameProperty, new CodePrimitiveExpression(dataContractName))); collectionContractAttribute.Arguments.Add(new CodeAttributeArgument(ImportGlobals.NamespaceProperty, new CodePrimitiveExpression(collectionContract.XmlName.Namespace))); @@ -1671,7 +1671,7 @@ private static CodeThisReferenceExpression ThisReference private static CodePrimitiveExpression NullReference { - get { return new CodePrimitiveExpression(null); } + get { return new CodePrimitiveExpression(null!); } } private CodeParameterDeclarationExpression SerializationInfoParameter @@ -1782,12 +1782,12 @@ private CodeMemberMethod GetSchemaStaticMethod new CodeTypeReferenceExpression(GetCodeTypeReference(typeof(XmlSerializableServices))), nameof(XmlSerializableServices.AddDefaultSchema), new CodeArgumentReferenceExpression(paramDeclaration.Name), - new CodeFieldReferenceExpression(null, TypeNameFieldName) + new CodeFieldReferenceExpression(null!, TypeNameFieldName) ) ); getSchemaStaticMethod.Statements.Add( new CodeMethodReturnStatement( - new CodeFieldReferenceExpression(null, TypeNameFieldName) + new CodeFieldReferenceExpression(null!, TypeNameFieldName) ) ); return getSchemaStaticMethod;