Friday, 17 December 2010

One way to return an assembly from a string input

Where T is the interface you have defined to use with the assembly you are passing in and returning;

public class Core
{
public static T GetClass<T>(string Assembly)
{
string[] strAssembly = Assembly.Split(Convert.ToChar("."));
System.Runtime.Remoting.ObjectHandle oObjectHandle;

oObjectHandle = System.Activator.CreateInstance(strAssembly[0].ToString(), Assembly);
T oIinsert = (T)oObjectHandle.Unwrap();
return oIinsert;
}
}

No comments:

Post a Comment