diff --git a/Speckle.InterfaceGenerator/AutoInterfaceGenerator.cs b/Speckle.InterfaceGenerator/AutoInterfaceGenerator.cs index 818cb7c..30cdfba 100644 --- a/Speckle.InterfaceGenerator/AutoInterfaceGenerator.cs +++ b/Speckle.InterfaceGenerator/AutoInterfaceGenerator.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Diagnostics; @@ -145,6 +145,11 @@ public class AutoInterfaceGenerator : ISourceGenerator 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 @@ public class AutoInterfaceGenerator : ISourceGenerator --codeWriter.Indent; codeWriter.WriteLine("}"); + if (implTypeSymbol.NullableAnnotation == NullableAnnotation.Annotated) + { + codeWriter.WriteLine("#nullable restore"); + } codeWriter.Flush(); stream.Seek(0, SeekOrigin.Begin);