usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacemyfrist{InterfaceTest {intADD (intAintb); } classHei:test { Public intADD (intAintb) {Try { returnA +b; } Catch(Exception ex) {return 0; } } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceconsoledll{classProgram {Static voidMain (string[] args) { stringDllPath = AppDomain.CurrentDomain.BaseDirectory +"MyFrist.dll"; varResource =System.Reflection.Assembly.LoadFrom (DllPath); foreach(var_everyinchResource. GetTypes ()) {if(_every. GetInterface ("Test") !=NULL) { varPlugin =Activator.CreateInstance (_every); Object[] Paramertors =New Object[] { -,2};//Parameter Collection varTemp=_every. GetMethod ("ADD"); Objectresult=temp. Invoke (plugin, paramertors); Console.WriteLine (result); } } } }}
C # dynamic Load DLL interface