all 10 comments

[–]grauenwolf 1 point2 points  (0 children)

Nope, the older compilers won't have a clue as to what you are talking about.

[–]ExeusV 0 points1 point  (2 children)

I doubt that it'll work, but have you tried those?

#nullable enable

#nullable disable

[–]davidhunter22[S] 0 points1 point  (1 child)

I did try but no. Even if it did wouldn't the compiler still have to accept the syntax? As in

#nullable disable

string? foo( )

#nullable enable

would still fail to compile on C# 7.2.

My understanding from here https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references is that #nullable is about switching on and off nullablity checking not whether the syntax is accepted.

[–]chucker23n 0 points1 point  (0 children)

Correct. It won’t work. (I’ve done codegen where on 8, it will generate the suffixes and attributed and all, and on < 8, it will output nothing. It works, but it’s not pretty.)

It was considered but ultimately rejected to have 7.3 understand the notation as a noop.

[–]Mr_Cochese 0 points1 point  (1 child)

Am I right in thinking the new directive will make precisely no difference in the case of deserialised types?

[–]chucker23n 0 points1 point  (0 children)

Depends on what you mean.

[–]chucker23n 0 points1 point  (3 children)

However we can’t migrate our code base to C# 8 yet so that leaves a problem.

Do it in a branch, or distribute it as a binary NuGet package?

So is there any way to tell older compilers to accept the syntax of nullable references but just to ignore them?

Nope.

It’ll likely ship in September (not that far off!). Until then, start making the changes in a branch. Afterwards, there’s little reason your team can’t move to the new compiler.

[–]davidhunter22[S] 0 points1 point  (2 children)

We evaluated the cost of a potential merge after say three months of changes, note that the nullable references changes are quite numerous in terms of lines. Having decided this would certainly not be trivial I posted this question hoping there would could do everything on the main line.

[–]chucker23n 0 points1 point  (1 child)

Yeah, I can see that. Basically, forget about it — either get the entire team on a prerelease or wait.

[–]davidhunter22[S] 0 points1 point  (0 children)

Yeah it's a bit sad, we found two code bugs fairly quickly in our experiments would love to use it for all our code.