Is is possible to get the name of property that the current class is assigned to in the class it was called from?
Let's say I've got three classes:
class Parent1
{
public Child myName;
public void Foo()
{
myName.Method();
}
}
class Parent2
{
public Child mySecondName;
public void Foo()
{
mySecondName.Method();
}
}
class Child
{
public void Method()
{
Log(__propertyName__);
}
}
I'd like to Log
the value myName
when the Method
is called from Parent1
and mySecondName
if the Method
is called from Parent2
.
Is it possible using reflection and not by passing names by string in argument (I want to use it only for the debugging purposes, I don't want to link those class together in any way)