Skip to content

Commit

Permalink
Suppress nullable warnings in Serialization.Schema
Browse files Browse the repository at this point in the history
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: #78036
  • Loading branch information
ViktorHofer committed Nov 22, 2022
1 parent f7e4f6d commit 0aed816
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0aed816

Please sign in to comment.