Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
I want a factory method that returns a Wotsit for different types of T. It needs to support multiple types, lookup a wotsit based on the return type, and support runtime registration of new types and associated wotsits, so the factory method needs to take the return type as a parameter. I can do this as long as T isn't a generic type. Unfortunately I need it to support generic types.
e.g. I can do this
Wotsit<Blah> myWotsit = WotsitFactory.getWotsit(Blah.class);
Blah result = myWotsit.doStuff();
but this doesn't work
Wotsit<List<Blah>> myWotsit = WotsitFactory.getWotsit(List<Blah>.class);
List<Blah> result = myWotsit.doStuff();
for (Blah blah : result) {
....
Yes, I know I can use Object, but I don't want to, that defeats the point of using generics in the first place. I might as well be using ******* void *
Can C# do this?
What I can do is create a non generic class that implements List<Blah> and then use something like
Comment