Skip to content

Instantly share code, notes, and snippets.

View szul's full-sized avatar
💻

Michael Szul szul

💻
View GitHub Profile
@szul
szul / DynamicFactoryLoading.cs
Last active August 29, 2015 14:20
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);
@szul
szul / DynamicMethodInvocation.cs
Last active August 29, 2015 14:20
Dynamic method invocation
/*
* You will need "using System.Reflection;"
* The variable "method" is a string that represents the case-sensitive name of the method to be called.
* The variable "context" in this instance is the HttpContext, but can be any variable(s) the method expects.
* In this example the called method returns a string, so the invocation is cast into a string, but this can change based on what the method returns.
*/
Type _t = this.GetType();
MethodInfo _methodInfo = _t.GetMethod(method);
string result = (String)_methodInfo.Invoke(this, new object[] { context });