标签:eric invoke null blog plugin get alt base using
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyFrist { interface Test { int Add(int a, int b); } class Hei : Test { public int Add(int a, int b) { try { return a + b; } catch (Exception ex) { return 0; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleDll { class Program { static void Main(string[] args) { string dllPath = AppDomain.CurrentDomain.BaseDirectory + "MyFrist.dll"; var resource = System.Reflection.Assembly.LoadFrom(dllPath); foreach (var _every in resource.GetTypes()) { if (_every.GetInterface("Test") != null) { var plugin = Activator.CreateInstance(_every); object[] paramertors = new object[] { 500, 2 };//参数集合 var temp=_every.GetMethod("Add"); object result=temp.Invoke(plugin, paramertors); Console.WriteLine(result); } } } } }
标签:eric invoke null blog plugin get alt base using
原文地址:http://www.cnblogs.com/testsec/p/6095803.html