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

后端 未结 1 493
耶瑟儿~
耶瑟儿~ 2021-01-24 07:38

In C# I can get Visual Studio to keep the delegate\'s argument names.
For example if I have:

public delegate void Blah(object myArg);
public event Blah Foo         


        
相关标签:
1条回答
  • 2021-01-24 07:56

    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.

    0 讨论(0)
提交回复
热议问题