[Proposal]: Unbound generic types in nameof
#8661
Replies: 6 comments
-
Finally! As of today I use a dummy internal type named nameof(A<_>)
nameof(Dictionary<_,_>.Count) |
Beta Was this translation helpful? Give feedback.
-
@koszeggy How do you use discards then, e.g. |
Beta Was this translation helpful? Give feedback.
-
@jnm2: interestingly enough, it doesn't cause any conflicts. I can simply use the regular discard even when switching on types (like here), and it's not interpreted as my dummy |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
🎉 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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
- 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
Beta Was this translation helpful? Give feedback.
All reactions