Created
January 27, 2017 08:37
-
-
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.
This file contains hidden or 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
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