I need to write a bunch of methods that accept parameters of type 1..N, for example:
int Foo<T1>(); int Foo<T1,T2>(); int Foo<T1,T2,T3>(); ... int Foo<T1,T2,T3...TN>();
Inside Foo() I would like to do something for each type, like
int Foo<T1,T2,T3>() { this.data = new byte[3];
Is there a way to parameterize this so that I don't edit all the Foo() variants, something similar to:
int Foo<T1,T2,T3>() { this.data = new byte[_NUMBER_OF_GENERIC_PARAMETERS]; }
Ideally, I would also like to get an array or a collection of types:
int Foo<T1,T2,T3>() { this.data = new byte[_NUMBER_OF_GENERIC_PARAMETERS]; // can do this Type [] types = new Type[] { T1, T2, T3 }; // but would rather do this Type [] types = _ARRAY_OR_COLLECTION_OF_THE_GENERIC_PARAMETERS; }
Coderbrien
source share