-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Proposal]: Unbound generic types in nameof
#8480
Comments
Finally! As of today I use a dummy internal type named nameof(A<_>)
nameof(Dictionary<_,_>.Count) |
@koszeggy How do you use discards then, e.g. |
From LDM notes:
Is this still the case and the LDT is now willing to take on the cost? Would implementing this feature make it cheaper to do a similar feature in |
@MgSam I don't think the view is that this is expensive anymore, and my view is that it's straightforward to address the mentioned corners. Back at the time, the corners were coming as an afterthought, but they're priced into my proposal and the implementation ends up as 40 lines of compiler code. I can't speak to the comparative cost of adding member lookup to |
nameof
nameof
🎉 LDM approved the proposal! A backup plan was also pre-approved. If preferable for implementation, we could do a version of this which did not provide lookup through generic type constraints. |
- Support Open-Generic-Types in 'nameof' expressions. roslyn#4902 and Support Open-Generic-Types in 'nameof' expressions. roslyn#4907 by @CyrusNajmabadi
- Allow open types in nameof roslyn#20450 by @alrz
Summary
Allows unbound generic types to be used with
nameof
, as innameof(List<>)
to obtain the string"List"
, rather than having to specify an unused generic type argument in order to obtain the same string.See https://github.com/dotnet/csharplang/blob/main/proposals/unbound-generic-types-in-nameof.md for detailed spec.
Design meetings
https://github.com/dotnet/csharplang/blob/main/meetings/2017/LDM-2017-11-06.md#roslyn-20450
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-10-16.md#unbound-generic-types-in-nameof
The text was updated successfully, but these errors were encountered: