[英]How to get trace of properties tree?
可以說我有這樣的事情:
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();
}
是否有可能實現方法GetPath()
,該方法將返回例如“ C1 in B1 in A1
”?
沒有內置的方法可以解決此問題。
您可以做的是:
OOP方式:在傳遞父/所有者類引用的位置定義ctor,以便可以在運行時確定。
使用Environment.StackTrace並僅獲取堆棧跟蹤(不知道這是否真的符合您的需求)
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.