Calling a static abstract method without a generic type [Answered]
If I have this code with a static abstract member
Bar
in the interface IFoo
, is there any way (besides reflection) to call Bar
on an instance of IFoo
without the explicit type of the instance? 12 Replies
I know it'd be trivial to do this using reflection, but like... it's reflection
Like
Bar
is there, it has to exist in the type of f
, but it's inaccessible without an explicit type, which is impossible to get with just an instance of something.Use an instance method
hmm
I mean that doesn't really solve the issue
Well, you're trying to use a static method like an instance method here
It doesn't seem like a realistic scenario
My suggestion is to rethink what you're trying to accomplish
Well I mean, this isn't a practical example. The only real use is that methods which call static abstract members have to have type parameters, which can become an issue if you either only have the interface type or if the type cannot be inferred and you have to manually write out some big declaration.
Though I agree that yes this is barely practical anyway
The only real use is that methods which call static abstract members have to have type parametersyes If you don't have this, you're using a square peg to go in a round hole
It's still slightly annoying
It should be
I mean... fair, there's a clear distinction between static and instance, but this still to me feels like one of the major drawbacks of static abstracts
✅ This post has been marked as answered!