I need to pass a list of types to a method, but I want to make sure (at compile time) that they all inherit from BaseType. Also, I don't know how many types need to be passed.
So, I decided that this would be a bad way:
public void DoSomething(params Type[] types)
So what I have been doing so far is something like this:
private void DoSomething(params Type[] types) public void DoSomething<T1>() where T1 : BaseType { DoSomething(typeof(T1)); } public void DoSomething<T1, T2>() where T1 : BaseType where T2 : BaseType { DoSomething(typeof(T1), typeof(T2)); } public void DoSomething<T1, T2, T3>() where T1 : BaseType where T2 : BaseType where T3 : BaseType{...}
You get the Idea. So the question is: can you make it a little prettier? Because it does not support an arbitrary number of types. And in my scenario, eight or more types would not be too unusual.
I want to use this to βmagicβ it , but the caller has no reference to the container.
generics c #
black_puppydog
source share