I have a set of some classes which are all capable of being constructored with an argument being an instance of a particular interface. Since they all can be constructed by this same object (and the process during which this construction happens is largely the same in all cases), I figured perhaps templating would work. Basically, I want to do something like this:
public static void dostuff<T, U> (List<T> items)
{
foreach (T item in items)
{
func(new U(item).SpecialMember);
}
}
Of course, that won't compile since U
is templated and thus lacks SpecialMember
as well as the T
constructor.
Basically, any given implementation of the inteface T
has certain features. U
is an implementation of T which has an additional feature that is needed *and* which can be constructed from an any instance of
U`.
Advice?