Open AArnott opened 3 years ago
The metadata has many
[Optional]
annotations on its inputs to help with this, but I don't know how consistently it is applied.
One place where [Optional]
is currently missing is on SafeHandle parameters.
This would be nice to have as a consuming library that has nullable enabled.
@JeremyKuhne, as nullable refs only apply for reference types, how often do you expect to be passing reference types into interop? Can you give a few examples of APIs that you use where a null ref is allowed and you'd like to see that expressed?
@AArnott Not looking for this for the [DllImport]
s themselves, looking for the wrappers you generate. Most notably for us this comes up with string
. CreateWindowEx
is an example where there are optional LPCWSTR
parameters.
We ought to be able to do that. CreateWindowEx
's parameter is annotated as optional in the metadata.
Can you give a few examples of APIs that you use where a null ref is allowed and you'd like to see that expressed?
Considering migrating my app from LibraryImport
to CsWin32
but not having the nullability annotations feels like a step down.
Originally posted by @jnm2 in https://github.com/microsoft/CsWin32/issues/129#issuecomment-781466704
If we annotate at all, we need to be consistent so users can trust that a parameter is required when we don't annotate it. The metadata has many
[Optional]
annotations on its inputs to help with this, but I don't know how consistently it is applied.