我正在包装一个包含数百个函数的本机库,在所有这些函数之上键入 DllImport 非常烦人。
有没有办法避免在每个函数上方编写这些丑陋/重复的属性?
public const string NativeDll = "mynativelib.dll";
[DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void foo1();
[DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void foo2();
[DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void foo3();
[DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void foo4();
...
[DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void fooN();