Type casting without instances #7889
Unanswered
ChristopherHaas
asked this question in
Language Ideas
Replies: 1 comment
-
There is currently no way in the language or runtime to conditionally constraint a generic type parameter within the body of a method. The closest you get today is via reflection. See: #6308 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose you have an interface with an abstract static method. Ex:
Then, inside another method, You may want to call this factory method, if possible. Something like:
However, it does not seem possible to describe this kind of runtime type testing in C# (without reflection, IL emit etc.). It would be beneficial for the overall abstract static in interfaces feature to allow some kind of typecasting without instances.
Am I missing something, or am I correct in concluding that this cannot currently be done?
Beta Was this translation helpful? Give feedback.
All reactions