Getting the typeof this to use in a generic method
I have a class with a method that requires a different class that has a generic method. How can I get the type of the first class to pass into the generic method?
7 Replies
foo.GenericMethod<Bar>
If I have any class that extends Bar, will they have to override the method to pass their own type in or no?
like if I had..
class Thing : Bar
for context, I want Bar to be an abstract class and for anything that inherits it to have Pass
workah
generally the solution for that is this:
its not a perfect solution since you could pass another T that inherits bar but its the best you can do in C# for now
Gotcha gotcha, thank you lots!
np
$close
If you have no further questions, please use /close to mark the forum thread as answered
The pattern is called CRTP if you want to read more about it.