C# 向委托动态添加非托管FunctionPointerAttribute

C# 向委托动态添加非托管FunctionPointerAttribute,c#,attributes,runtime,marshalling,C#,Attributes,Runtime,Marshalling,我有一个CreateDelegate方法,我使用 Marshal.GetDelegateForFunctionPointer(func_addr, CreateDelegate()) 它工作得很好,但现在我需要处理这个调用。 所以func_addr是一个“调用约定.ThisCall”。静态而言,这是可行的: [UnmanagedFunctionPointer(CallingConvention.ThisCall)] delegate int d_Add(IntPtr _this, int x,

我有一个CreateDelegate方法,我使用

Marshal.GetDelegateForFunctionPointer(func_addr, CreateDelegate())
它工作得很好,但现在我需要处理这个调用。 所以func_addr是一个“调用约定.ThisCall”。静态而言,这是可行的:

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
delegate int d_Add(IntPtr _this, int x, int y);
...
var value = Marshal.GetDelegateForFunctionPointer<d_Add>(Addfunc_addr)(_this, 50, 100);
// return 150;
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
代表int d_Add(IntPtr_this,intx,inty);
...
var value=Marshal.GetDelegateForFunctionPointer(Addfunc\u addr)(\u this,50100);
//返回150;
我想在运行时将UnmanagedFunctionPointerAttribute添加到来自CreateDelegate的新委托中,或者以任何方式将委托封送为ThisCall,这可能吗

我找到了这个线程:但在我的例子中,它不是一个自定义属性