There are two project, one C++ CLI and other is C#.
The C# project has reference to C++ CLI project.
In C# I want to do this :
//method signature is somemethod(dynamic data);
somemethod("haaaii");
Now the method which is in C++ CLI project must handle this.
How to declare this method in C++ CLI ?
Also how to detect data type in C++ CLI ?
To get a method signature which C# sees as dynamic
:
void TestMethod( [System::Runtime::CompilerServices::DynamicAttribute] System::Object^ arg )
{
}
But if you just want to accept all types, you can simply use System::Object^
. The attribute is misleading, as it implies semantics which you will have a very hard time providing.
To discover the actual data type, use arg->GetType()
. You can then use all the power of reflection and/or the DLR for discovering and invoking members at runtime.
Slightly more useful is to use the attribute on a return type, since then C# will infer dynamic
semantics when the var
keyword is used.
[returnvalue: System::Runtime::CompilerServices::DynamicAttribute]
System::Object^ TestReturn( void )
{
return 1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With