MelGrubb / BuilderGenerator

A source-generator-based implementation of the Builder pattern
https://melgrubb.github.io/BuilderGenerator/
MIT License
36 stars 8 forks source link

CS8669 warning for types with nullable properties #46

Open j-mok opened 2 months ago

j-mok commented 2 months ago

I've got a .NET 8/C# 12 project with nullable references enabled and when I use BuilderGenerator on a class that has properties with nullable reference types, the generated builder becomes a source of compiler warnings:

FooDtoBuilder.g.cs(102,77): 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.

This seems to be a consequence of a combination of #nullable disable in the generated code and the keeping the ? suffix on data fields:

public System.Lazy<string?> BazProperty = new System.Lazy<string?>(() => default(string?));

Can this be fixed somehow?