單獨的文件夾保持他們的方法就可以了。你會加載自己使用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