0
我試圖迫使痛飲使用自己的包裝圍繞「默認」生成的包裝,這裏有一個例子...各地SWIG包裝定製包裝
我有以下的「接口」代碼:
template<typename T>
class Expected
{
public:
T Value();
};
%template(Expected_Int) Expected<int>;
%template(Expected_Bool) Expected<bool>;
%template(Expected_Void) Expected<void>;
和我自己的C#實現(我自己的包裝)
public class Expected
{
public Expected(Expected_Void private) {...}
}
在其他班,我用的是預期收益值,像這樣的「預期setHandle(IViewHandle *手柄)」,並痛飲生成驗證碼:
public override Expected_Void setHandle(IViewHandle handle) {
Expected_Void ret = new Expected_Void(luciadsdkPINVOKE.ViewContext_setHandle(swigCPtr, IViewHandle.getCPtr(handle)), true);
if (luciadsdkPINVOKE.SWIGPendingException.Pending) throw luciadsdkPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
現在,我希望生成下面的C#代碼(大約有SWIG包裝我自己的包裝)
public override Expected setHandle(IViewHandle handle) {
Expected_Void ret = new Expected_Void(luciadsdkPINVOKE.ViewContext_setHandle(swigCPtr, IViewHandle.getCPtr(handle)), true);
if (luciadsdkPINVOKE.SWIGPendingException.Pending) throw luciadsdkPINVOKE.SWIGPendingException.Retrieve();
return Expected(ret);
}
這可能嗎?
感謝
的解
%typemap(csout,excode=SWIGEXCODE) Expected<void> {
IExpected ret = new IExpected($imcall, true);$excode
return ret;
}
%typemap(cstype) Expected<void> "IExpected"
謝謝, 我將我的解決方案添加到帖子中。你離我的解決方案還不太遠;-) – CDZ
好的,我看到你的解決方案。如果您沒有創建IExpected來解決這個問題,那顯然是最好的。 無論如何,我注意到我在回答中犯了一個錯誤,我編輯這個帖子以防萬一。 –
另一個提示,只是要知道,這個typemap將適用於所有返回預期的方法。要專注於一種方法,您需要指定方法名稱,就像我一樣。 –