lets say I have something like this:
class Program
{
static void Main(string[] args)
{
A A1 = new A();
A1.B1.C1.GetPath();
}
}
class A
{
public B B1 { get; set; }
public B B2 { get; set; }
}
class B
{
public C C1 { get; set; }
}
class C
{
public string GetPath();
}
Is there possibility to implement method GetPath(), that would return for example “C1 in B1 in A1” ?
There is no built-in way to chieve this.
What you can do is:
OOP way: define ctor where you pass parent/holder class reference, so it can be figured out at runtime.
use of Environment.StackTrace and get just stack trace (don’t know if this fits your needs actually)
Hope this helps.