C# Reflection

This class can instantiate any class, from any namespace, with any kind and amount of parameters.
You only need to have in the instantiated class constructor, the code you need to execute without having to do a reflection on methods of the class and call them in a second step:

public class Factory

{

  public Factory(object[] args, string className, string nameSpace)

  {

    string type = namespace + “.” + className;

    ((Assembly)assemblies[type]).CreateInstance(type,false,BindingFlags.CreateInstance,null,args,null,null);

  }

}

Advertisements