In C# and VB.Net I can use the CallerMemberNameAttribute to get the name of the invoker as a string:
public void Caller([CallerMemberName]string memberName = "")
{
Debug.Print(memberName);
}
I would like to do the same in C++/CLI but somehow I cannot get it working. Tried several constructions and I am starting to wonder whether the C++/CLI compiler supports this attribute.
Here is a (simplified) implementation:
using namespace System::Runtime::CompilerServices;
public ref class InvokeExample
{
Invoke([CallerMemberName][Optional]String^ name)
{
Debug::Print(name);
}
}
When invoking this method in a C# application the value of name is null. Also tried with the attribute DefaultParameterValue but it didn't help either. Now running out of ideas.
Obvious answer would be, why not implementing in C#? Well, in this specific case I am limited to C++/CLI.