BuilderTestSample icon indicating copy to clipboard operation
BuilderTestSample copied to clipboard

Would love to see this converted to use Nullable Reference Types

Open StevenTCramer opened this issue 4 years ago • 3 comments

I am using nullable reference types on a Pulumi IaC project where I use the builder pattern. But find it difficult to get dotnet to figure out when items are not null.

The Builder Pattern is a delayed constructor. The things it is supposed to build will be null until the Build() method has been executed. But after Build they won't be null.

I try to help by using MemberNotNull attributes but that seems to just kick the can down the road only level.

StevenTCramer avatar Mar 22 '21 17:03 StevenTCramer

If we implement #8 then it will be easy to use nullable types.

Arnab-Developer avatar Jun 17 '21 07:06 Arnab-Developer

Adding the <Nullable>enable</Nullable> is what is needed but there is a lot of warnings of course. Those errors can be removed by giving the different instances "default" values. But I think it's not very good practice doing so.

The question is also what would a "default" value be for example for a Customer object. And if we create two default Customer objects, are they considered equal or not because the have the same values or are they only equal if they have the same reference.

But if someone want's to play with nullable references you can just add <Nullable>enable</Nullable> in BuilderTestSample.csproj under the first <PropertyGroup> and build it.

Not sure this is worth it adding in the main repository.

wgaffa avatar Jun 17 '21 17:06 wgaffa

You can check my attempt of this kata.

https://github.com/Arnab-Developer/BuilderTestSample/tree/Arnab-Developer/16-06-2021

I have used null reference type in that.

Arnab-Developer avatar Jun 17 '21 18:06 Arnab-Developer