SHARE
TWEET

Untitled

a guest Feb 27th, 2020 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public TResult GetObject<TResult>(string assemblyNameString, string className, params object[] args)
  2.         {
  3.             AssemblyName assemblyName = new AssemblyName(assemblyNameString);
  4.  
  5.             Assembly assembly = LoadAssembly(assemblyName) ?? Assembly.Load(assemblyName);
  6.  
  7.             if (assembly == null)
  8.             {
  9.                 throw new Exception(String.Format("Unable to load assembly: {0}", assemblyNameString));
  10.             }
  11.  
  12.             Type type = assembly.GetType(className);
  13.  
  14.             if (type == null)
  15.             {
  16.                 throw new Exception(
  17.                     String.Format("Unable to find class name {0} in assembly {1}", className, assemblyNameString));
  18.             }
  19.  
  20.             var obj = Activator.CreateInstance(type, args);
  21.  
  22.             return (TResult)obj;
  23.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top