Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit nullable ref annotated code #130

Open
AArnott opened this issue Feb 18, 2021 · 6 comments
Open

Emit nullable ref annotated code #130

AArnott opened this issue Feb 18, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@AArnott
Copy link
Member

AArnott commented Feb 18, 2021

When the project langversion is >= 8, could you also put #nullable enable or at least #nullable annotations in the file or around the parameter declaration and use SafeHandle? as the parameter type so that IntelliSense shows me that nulls are anticipated?

Originally posted by @jnm2 in #129 (comment)

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.

@AArnott AArnott added the enhancement New feature or request label Mar 9, 2021
@jnm2
Copy link
Contributor

jnm2 commented Nov 16, 2021

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.

AArnott added a commit that referenced this issue May 6, 2022
@JeremyKuhne
Copy link
Member

This would be nice to have as a consuming library that has nullable enabled.

@AArnott
Copy link
Member Author

AArnott commented Sep 8, 2022

@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?

@JeremyKuhne
Copy link
Member

@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.

@AArnott
Copy link
Member Author

AArnott commented Sep 9, 2022

We ought to be able to do that. CreateWindowEx's parameter is annotated as optional in the metadata.

@rampaa
Copy link

rampaa commented Jun 19, 2024

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?

FindWindowW

Considering migrating my app from LibraryImport to CsWin32 but not having the nullability annotations feels like a step down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants