0

I have a set of code that takes in a value (a string) that contains the exact name of a class that I need to reference. The class to be referenced is in a separate DLL file (I already put the using lib_vxmanager; for the DLL). I simply need to get the string to a proper type that can be used to do something like this:

Classname class = new Classname();

Code sample:

public void Classreference(string reference_name)
{
    string Classname = reference_name.Split('{','}')[0]; //This is the classname
    //Convert name to type here
}
kyrylomyr
  • 12,192
  • 8
  • 52
  • 79
Varscott11
  • 13
  • 3

2 Answers2

2

You need to use the Activator:

var obj = Activator.CreateInstance("Your assembly name", "Your class name");
kyrylomyr
  • 12,192
  • 8
  • 52
  • 79
0

You can try Assembly.CreateInstance and Activator.CreateInstance.