c# - Pass Type as a parameter to a function -
i have dictionary object
dictionary<string, type> dict = new dictionary<string, type>();
i have baseclass , number of child-classes, say: childclass1, childclass2, etc. dictionary has values:
dict.add("type1", typeof(childclass1)); dict.add("type2", typeof(childclass2));
my question - there way this:
baseclass c = new <<get type dict: dict[type1]>>()?
i want make solution more flexible, i'm not sure if that's possible @ all. thanks!
var c = (baseclass)activator.createinstance(dict["type1"]);
Comments
Post a Comment