I need to call a function to call user's dll in C#.
For example, when user makes a abc.dll with class ABC, I want to load the dll to run the methods xyz(a) in the class.
object plugInObject = node.GetPlugInObject("abc.dll", "ABC");
plugInObject.runMethod("xyz", "a");
How can I implement those functions in C#?
ADDED
This is 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);
}
}