This question already has an answer here:
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)
{
Type[] type={Type.GetType("System.String"),ProtoType};
Type resolve = typeof(ResolvedChainSubscriber <,>).MakeGenericType(type);
ResolvedChainSubscriber<string, Activator.CreateInstance(resolve)> obj1 = new ResolvedChainSubscriber<string, Activator.CreateInstance(resolve)>();
}
However, this doesn't seem to be working.
Aucun commentaire:
Enregistrer un commentaire