I could very will be imagining things, but I seem to recall in Java that I can declare a field or parameter as such:
public class BarHandler{
public Class<? extends Foo> fooType;
public ProcessedBar Process(string xml){
Foo foo = fooType.GetInstance();
return foo.process(xml)
}
}
This can be useful for factory style systems where you have to be able to generate new instances of the type in question for example.
I am trying to figure out if there is an analog to this in C#, or if possibly this is just something that is available within Java.
Here’s a variation of 280Z28’s answer. I’ve renamed the “Type” class to “Factory”, since in my version it exposes a
GetInstancemethod instead of aValueproperty of typeType. This uses 2 generic parameters and generic constraints to enforce the rules that were in the original answer’s constructor for the Type class.