Last active
August 29, 2015 14:20
-
-
Save szul/7bdf511c57a0cc984137 to your computer and use it in GitHub Desktop.
Dynamic factory loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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