Skip to content

Instantly share code, notes, and snippets.

@ioncodes
Created January 27, 2017 08:37
Show Gist options
  • Save ioncodes/f06f2617c38dbbc3aebf54aed76a168e to your computer and use it in GitHub Desktop.
Save ioncodes/f06f2617c38dbbc3aebf54aed76a168e to your computer and use it in GitHub Desktop.
Loads an assembly and executes the method with the specified arguments. Has support for BindingFlags.
public static object ExecuteMethod(string asm, string stype, string smethod, BindingFlags flags, object[] arguments)
{
Assembly assembly = Assembly.LoadFile(asm);
Type type = assembly.GetType(stype);
MethodInfo method = type.GetMethod(smethod, flags);
return method.Invoke(null, arguments);
// Usage: (int)ExecuteMethod("test.dll", "Namespace.Class", "CalculateTwoInts", BindingFlags.Static | BindingFlags.Public, new object[] {1,2});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment