How can I create .Net extension methods by C++/CLI?

后端 未结 1 1161
情书的邮戳
情书的邮戳 2020-12-29 06:01

In C#, extension methods can be created by

public static class MyExtensions {
    public static ReturnType MyExt(this ExtType ext) {
        ...
    }
}
         


        
1条回答
  •  时光说笑
    2020-12-29 06:31

    You just have to decorate the method and the containing class with ExtensionAttribute:

    using namespace System::Runtime::CompilerServices;
    ...
    
    [ExtensionAttribute]
    public ref class MyExtensions abstract sealed {
        public:        
            [ExtensionAttribute]
            static ReturnType MyExt(ExtType ^ext) {
                ...
            }
    };
    

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