Tuesday, 14 April 2009

Dynamic Class Instantiation

public void DynamicInstantiation(string fullname)

{  

    // Assign the fully qualified name to a string variable  

    // fullname = "Namespace.ClassName";  

    // Or to get the namespace dynamically  

    // string fullname = object.GetType().Namespace + ".ClassName";   

    // Then Create the object  

    SampleClass dynclass = (SampleClass)System.Activator.CreateInstance(Type.GetType(fullname));

}

No comments: