Anton V. Ruzhov

hi, I wrote classes:
Code Snippet



class A
{
}

abstract class A<T, U>: A
{
}

class A<T, U, V>: A
{
}

then I'm trying to get instance of A<T,U,V>:

static A GetA(Type t, Type u, Type v)
{
Type a = typeof(A<>).MakeGenericType(t, u, v);
return (A)Activator.CreateInstance(a);
}

That func doesn't compile with error "The non-generic type 'Karioth.Test.A' cannot be used with type arguments" at marked point.

How can I create an instance of A<T,U,V>
Thanks.



Re: Visual C# Language typeof(A<>) and compiler error

Matthew Watson

Put commas to indicate the number of type arguments if there is more than one, like this:

static A GetA(Type t, Type u, Type v)
{
Type a = typeof(A<,,>).MakeGenericType(t, u, v);
return (A)Activator.CreateInstance(a);
}





Re: Visual C# Language typeof(A<>) and compiler error

Karioth

Thanks a lot! It works Smile