Tmds.DBus
Tmds.DBus copied to clipboard
Codegen not compatible with all "nullable contexts"
The default "nullable context" for newly-generated C# projects targeting .NET 6 is now set to "enable" at the project level; this means all code generated by the dotnet-dbus codegen
command will receive the context that is set for the entire project unless it is overwritten at the source file level.
This means that every time the generated code tries to assign null
to a reference type, we get a compiler warning. When following along with the example included in the README.md file, for example, I observed the same warning 81 times:
warning CS8625: Cannot convert null literal to non-nullable reference type.
For reference, I have included the following to provide more information on this issue: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-reference-types#setting-the-nullable-context
Given that the codegen
command has no knowledge of the C# project it will be generating code for, I propose we fix this issue with one of the following solutions:
- Disable the nullable context for all
codegen
-generated source files by prepending "#nullable disable
" to the top of each file - Add a
--nullable
option for thecodegen
command that optimizes the generated code to take advantage of new nullable context features. (This obviously requires more work)
I prefer the second option.
Do you want to make a PR for one of these options?