Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions InterfaceGenerator/AutoInterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("{");

Expand All @@ -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);
Expand Down