Replies: 3 comments
-
Proposed here with more examples. |
Beta Was this translation helpful? Give feedback.
-
This feels very intuitive which is always a great sign for a new feature. I would like to see that. Great idea! |
Beta Was this translation helpful? Give feedback.
-
I disagree. I don't think that this belongs as a part of the language given that it's basically shorthand for reflection. I'd rather see better reflection APIs accepted into the BCL or published via NuGet that would simplify these scenarios. I have written extension methods that allow for such simple interrogation of generic types. I've submitted them to the CoreFX repo but it has stalled. I have reference implementations that I wrote some time ago if you want to peruse: https://github.com/dotnet/corefx/issues/644 if (type.ImplementsInterface(typeof(IEnumerable<>), out var underlyingType)) {
// do stuff here
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
#356 would allow typeof expressions as a pattern to switch on,
It would be nice to also be able to use discard and var patterns inside a typeof pattern,
Note:
t is typeof(Nullable<>)
andt is typeof(Nullable<_>)
are matching against different types, i.e. the former only matches open types while the latter matches any closed type ofNullable<T>
.Open question: should we generate a call to
GetTypeInfo()
on theType
first?Open question: when combined with an as-pattern, what is the type of the variable?
Type
orTypeInfo
?Beta Was this translation helpful? Give feedback.
All reactions