Articles :: View

Convert string to Type in C#

You must have the full namespace in your string:

Type type = Type.GetType("Your.Namespace.Class"); //target type

object o = Activator.CreateInstance(type); // an instance of target type
IModule your = (IModule)o;
DefaultModule = your;


Comments

Be the first to add a comment!