Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Support C#8 NRT (Nullable Reference Types) in generated code #183

@amis92

Description

@amis92

It was brought to my attention that generating code in NRT-enabled projects raises warnings.

Reference: amis92/RecordGenerator#110


From the issue linked above:

Looks like the dotnet team decided auto-generated code needs to explicitly opt-in into nullable reference types:

public partial class TestClass
{
    public string? SomeTestProperty { get; }
}

In a project with

<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>

this generates without issues and is actually usable, but the following compiler warning is listed for the generated file. One warning per line that uses ? on a reference type.

Warning CS8669 The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.


What can/should we do about it? We'll definitely need to get aware of the Nullable project property. What else can we do to simplify/enable nullable generated code?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions