Reputation: 18097
What would be correct way to create new instance of the class from class type? The code below do not work, CreateInstance
accepts only strings.
Type converter=null;
converter = convertApiModelBase.Type;
return Assembly.GetExecutingAssembly().CreateInstance(converter);
Upvotes: 0
Views: 122
Reputation: 1202
As explained in http://msdn.microsoft.com/en-us/library/aa329906%28v=vs.71%29.aspx
With the code you attached, use the The Type.FullName of the type to locate.
return Assembly.GetExecutingAssembly().CreateInstance(converter.FullName);
Upvotes: 0
Reputation: 174289
return Activator.CreateInstance(convertApiModelBase.Type);
Upvotes: 2