Skip to content

Instantly share code, notes, and snippets.

@szul
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szul/7bdf511c57a0cc984137 to your computer and use it in GitHub Desktop.
Save szul/7bdf511c57a0cc984137 to your computer and use it in GitHub Desktop.
Dynamic factory loading
/*
* You will need "using System.Reflection;"
* This method allows you to dynamically load a specific factory that inherits from a base factory.
* The variable "factoryAssembly" is a string that represents the path to the factory DLL.
* The variable "factoryClass" is a string that represents class to be instantiated.
*/
public BaseFactory GetFactory(string factoryAssembly, string factoryClass)
{
Assembly assembly = Assembly.LoadFile(factoryAssembly);
Type type = assembly.GetType(factoryClass);
object obj = Activator.CreateInstance(type);
return (BaseFactory)obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment