Return a dynamic object in C ++ / CLI in C #

I have a C ++ / CLI project that wraps a large number of classes - and classes have their own metadata system. Therefore, I would like to return a dynamic object in order to simplify some use cases in C #. But I do not see how to do this in C ++.

In C #, I can write the following:

dynamic TestThisOut()
{
    return null;
}

void mork()
{
    var d = TestThisOut();
    d.Fork();
}

I would like to write TestThisOut()in C ++ / CLI, so that I can use it in the same way as in the "mork" function above (ie no need to type a dynamic keyword). Is it possible?

+3
source share
2 answers

++/cli, , #. #. :

++/CLI , Object ^. System:: Runtime:: CompilerServices:: DynamicAttribute. .

, :

namespace ClassLibrary1 
{
    using namespace System;
    using namespace System::Dynamic;

    public ref class Class1 : public DynamicObject
    {
    public:
        [System::Runtime::CompilerServices::Dynamic]
        static property Object^ Global
        {
        public:
            Object^ get()
            {
                return gcnew Class1();
            }
        }

    public:
        String^ Test()
        {
            return "Test";
        }
    };
}

#:

Console.WriteLine( ClassLibrary1.Class1.Global.Test() );
+4

dyanmic - # 4.0. ++ CLI ( VB.NET).

++ CLI, impromptu-interface . .

+2

All Articles