diff --git a/InterfaceGenerator/AutoInterfaceGenerator.cs b/InterfaceGenerator/AutoInterfaceGenerator.cs index e4ec264..ae04430 100644 --- a/InterfaceGenerator/AutoInterfaceGenerator.cs +++ b/InterfaceGenerator/AutoInterfaceGenerator.cs @@ -145,6 +145,11 @@ private string GenerateInterfaceCode(INamedTypeSymbol implTypeSymbol, AttributeD var interfaceName = InferInterfaceName(implTypeSymbol, attributeData); var visibilityModifier = InferVisibilityModifier(implTypeSymbol, attributeData); + //https://stackoverflow.com/questions/55492214/the-annotation-for-nullable-reference-types-should-only-be-used-in-code-within-a fix for nullable + if (implTypeSymbol.NullableAnnotation == NullableAnnotation.Annotated) + { + codeWriter.WriteLine("#nullable enable"); + } codeWriter.WriteLine("namespace {0}", namespaceName); codeWriter.WriteLine("{"); @@ -163,6 +168,10 @@ private string GenerateInterfaceCode(INamedTypeSymbol implTypeSymbol, AttributeD --codeWriter.Indent; codeWriter.WriteLine("}"); + if (implTypeSymbol.NullableAnnotation == NullableAnnotation.Annotated) + { + codeWriter.WriteLine("#nullable restore"); + } codeWriter.Flush(); stream.Seek(0, SeekOrigin.Begin);