I need to call a function to call a custom dll in C #.
For example, when a user creates abc.dll with an ABC class, I want to load the DLL to run the xyz (a) methods in the class.
object plugInObject = node.GetPlugInObject("abc.dll", "ABC"); plugInObject.runMethod("xyz", "a");
How to implement these functions in C #?
ADDED
This is the plugin code, and the dll is copied as plugin / plugin.dll.
namespace HIR { public class PlugIn { public int Add(int x, int y) { return (x + y); } } }
This is the one that calls this plugin.
using System; using System.Reflection; class UsePlugIn { public static void Main() { Assembly asm = Assembly.LoadFile("./plugin/plugin.dll"); Type plugInType = asm.GetType("HIR.PlugIn"); Object plugInObj = Activator.CreateInstance(plugInType); var res = plugInType.GetMethod("Add").Invoke(plugInObj, new Object[] { 10, 20 }); Console.WriteLine(res); } }
source share