Keep the delegate argument names when compiling C++/CLI for .Net

左心房为你撑大大i 提交于 2019-12-02 05:33:51

The question has no hint at the real problem and I could not get a repro. But later realized what might be happening, the C++ compiler is different from other managed compilers, and MSIL, it doesn't require parameters to be named in declarations. That panned out:

namespace CppClassLibrary {
    public ref class Example {
    public:
        delegate void Blah(int, int, int, int);
        event Blah^ Foo;
    };
}

Produces this auto-generated event handler in C#:

    void test_Foo(int A_0, int A_1, int A_2, int A_3) {
        throw new NotImplementedException();
    }

Looks like a slamdunk explanation. You simply forgot to name the parameters in the delegate declaration, the C++ compiler is forced to synthesize them in order to write correct MSIL. Easy to fix of course.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!