单独的文件夹保持他们的方法就可以了。你会加载自己使用Assembly.LoadFrom
合适的仪器代理组件。然后使用反射来创建该程序集类的实例,并拨打电话:
Assembly assm = Assembly.LoadFrom("c:\\Versions\\Version01\\instrument-proxy.dll");
Type yourClassType = assm.GetType("YourClass");
object yourClassObj = Activator.CreateInstance(yourClassType);
object Result = yourClassType.InvokeMember("DoSomething",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
yourClassObj,
args);
为了避免反射调用InvokeMember
你可以尝试用接口:
Assembly assm = Assembly.LoadFrom("c:\\Versions\\Version01\\instrument-proxy.dll");
Type yourClassType = assm.GetType("YourClass");
YourInterface interf = (YourInterface)Activator.CreateInstance(yourClassType);
interf.DoSomething();
接口将需要在一个单独的组件,你可以从你platform
引用。所有instrument-proxies
必须针对相同版本的接口组件进行编译。
如果您的仪器代理无法找到非托管Instrument.dll
你可以先使用前显式装载它:
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
IntPtr pDll = LoadLibrary(@"PathTo_Instrument.dll");
免费/卸载它,你就大功告成了之后:
[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);
哇!这正是我所期待的。其实我没有相信你的答案,然后我尝试了。太棒了。 – Archeg 2012-04-12 10:36:11