我有一個interop類,添加功能非常麻煩,因爲它涉及很多行。比方說,我需要有方法,通過ID我得讓你的ID如下:如何根據VS2013的委託定義生成C#委託,方法等?
public class MyInterop
{
public class WCFDTypes
{
//....
public delegate int GetInt_Delegate(int id);
//...
}
public class DTypes
{
//....
public delegate int DotNetInterface_GetInt_Delegate(int id);
//...
}
public WCFDTypes.GetInt_Delegate GetInt;
//...
private DTypes.DotNetInterface_GetPlotLabel_Delegate Nat_GetInt;
//...
public MyInterop(string moduleName)
{
DelegateBuilder builder = new DelegateBuilder(moduleName);
//...
Nat_GetInt = Build<DTypes.DotNetInterface_GetInt_Delegate>(builder);
//..
}
//...
GetInt = (int id) =>
{
return NatGetInt(id);
}
public MyInterop(string moduleName)
{
//...
Nat_GetInt = Build<DTypes.DotNetInterface_GetInt_Delegate>(builder);
//..
}
public MyInterop(MyApplication, string address)
{
//...
GetInt = client.GetInt;
//..
}
}
解釋這已經超出了這個問題的範圍。我只想知道如何生成一些東西,即使沒有返回類型或參數只是非變量部分(當然基於像GetInt這樣的函數名)來糾正位置(包括內部類,2個方法聲明和2個構造函數)。
我正在查看片段,但我發現的例子非常基本。
這當然是最糟糕的做法。爲什麼不能使用[DllImport]或C++/CLI包裝程序完全不清楚。 –
這不是我的代碼。正如我所說,這超出了這個問題的範圍。 –
加上它使用本機dll的DllImport。也適用於WCF的外部插件。 –