Poul K. Sørensen
Poul K. Sørensen

Reputation: 17530

How to do a Expression.New for a generic type where GenericType Arguments are not know at compile time

public MyType<T,T1,T2>
{

}

I need to do a Expression.New(typeof(MyType<,,>))

At compile time I do not know T,T1,T2. The expression new is inside a method

Expression CreateExpression(Type t, Type t1)
{
     Type t2 = Lookup(t,t1);

     return Expression.New(typeof(MyType<t,t1,t2>), ...constructorparams...);
}

I made the example as simple as possible for the sake of the question. Anyone know a way to do this?

Upvotes: 1

Views: 647

Answers (1)

Poul K. S&#248;rensen
Poul K. S&#248;rensen

Reputation: 17530

I found out I can do this:

    var t = typeof(C1EntitySet<,,>);
    t.MakeGenericType(new Type[]{t,t1,t2});

Upvotes: 1

Related Questions