public static DynaClassInfo GetClassReference(string AssemblyName, string ClassName) { if (ClassReferences.ContainsKey(AssemblyName) == false) { Assembly assembly; if (AssemblyReferences.ContainsKey(AssemblyName) == false) { AssemblyReferences.Add(AssemblyName, assembly = Assembly.LoadFrom(AssemblyName)); } else { assembly = (Assembly)AssemblyReferences[AssemblyName]; } // Walk through each type in the assembly foreach (Type type in assembly.GetTypes()) { if (type.IsClass == true) { // doing it this way means that you don't have // to specify the full namespace and class (just the class) if (type.FullName.EndsWith("." + ClassName)) { DynaClassInfo ci = new DynaClassInfo(type, Activator.CreateInstance(type)); ClassReferences.Add(AssemblyName, ci); return(ci); } } } throw (new System.Exception("could not instantiate class")); } return((DynaClassInfo)ClassReferences[AssemblyName]); }
public static object InvokeMethod(DynaClassInfo ci, string MethodName, Object[] args) { // Dynamically Invoke the method Object Result = ci.type.InvokeMember(MethodName, BindingFlags.Default | BindingFlags.InvokeMethod, null, ci.ClassObject, args); return(Result); }
// --- this is the method that you invoke ------------ public static object InvokeMethod(string AssemblyName, string ClassName, string MethodName, Object[] args) { DynaClassInfo ci = GetClassReference(AssemblyName, ClassName); return(InvokeMethod(ci, MethodName, args)); }