J
jon
I'm trying to write a block of code that can create an instance of a
generic object, with the Type coming in as a dynamic string. It isn't
working yet. Any advice how I can dynamically create the appropriate
object to pass into the generic's constructing <T,U>?
-------------------------------
// fully qualified types as string
string type1Str = "ns1.ns2.control1, software.lib1";
string type2Str = "ns1.ns2.control2, software.lib1";
// create type objects
Type type1Type = Type.GetType(type1Str);
Type type2Type = Type.GetType(type2Str);
// try to create generic object passing in dynamic types
// this next line doesn't compile because of "type1Type" not being
appropriate here
GenericObj<type1Type, type2Type> genericObj = new
GenericObj<type1Type, type2Type>();
public class GenericObj<T,U> {
......
}
generic object, with the Type coming in as a dynamic string. It isn't
working yet. Any advice how I can dynamically create the appropriate
object to pass into the generic's constructing <T,U>?
-------------------------------
// fully qualified types as string
string type1Str = "ns1.ns2.control1, software.lib1";
string type2Str = "ns1.ns2.control2, software.lib1";
// create type objects
Type type1Type = Type.GetType(type1Str);
Type type2Type = Type.GetType(type2Str);
// try to create generic object passing in dynamic types
// this next line doesn't compile because of "type1Type" not being
appropriate here
GenericObj<type1Type, type2Type> genericObj = new
GenericObj<type1Type, type2Type>();
public class GenericObj<T,U> {
......
}