我正在尝试找到一种方法来为swig生成的函数添加代码.我使用了类型映射来扩展类,但在文档中找不到有关扩展特定函数的任何内容.
给出以下swig接口文件:
%module Test %{ #include "example.h" %} %typemap(cscode) Example %{ bool 64bit = SizeOf(typeof(System.IntPtr)) == 8; static string Path = 64bit ? "/...Path to 64 bit dll.../" : "/...Path to 32 bit dll.../"; %} %include "example.h"
我得到以下C#代码:
public class MyClass : global::System.IDisposable { ... bool 64bit = SizeOf(typeof(System.IntPtr)) == 8; static string Path = 64bit ? "/...Path to 64 bit dll.../" : "/...Path to 32 bit dll.../"; ... public static SomeObject Process(...) { // Function defined in example.h <- I would like to add some code here. SomeObject ret = new SomeObject(...); } ... }
我想在函数Process中添加一些代码,这段代码是一个调用,SetDllDirectory(Path)
根据平台类型加载正确的dll.这需要在Process()
通话中发生.
任何帮助是极大的赞赏!