instantiating a generic class data type known at runtime

35 views Asked by At

I have a generic class in C# which has 2 data types public class ResolvedChainSubscriber < K, V>, now I have to create an instance of this class, but the data type of one of the arguments will only be known at runtime. I have it stored as "Type Prototype"

public static Object SubsciberTopic(Type ProtoType, Object obj)
{
    Type[] type={Type.GetType("System.String"),ProtoType};
    Type resolve = typeof(ResolvedChainSubscriber <,>).MakeGenericType(type); 
    Object obj1=Activator.CreateInstance(resolve);
     //now i want to typecast the parameter obj and store it in the new variable obj1
    obj1=(some statement here)obj;


}
0

There are 0 answers