在我當前的項目,我不控制的方法把我這種類型的對象:如何篩選遞歸對象?
public class SampleClass
{
public SampleClass();
public int ID { get; set; }
public List<SampleClass> Items { get; set; }
public string Name { get; set; }
public SampleType Type { get; set; }
}
public enum SampleType
{
type1,
type2,
type3
}
我在TreeView
顯示這些數據,但我想,只顯示SampleClass
對象結束路徑他們的Type
屬性設置爲type3
,無論這個葉子的深度如何。
我完全不知道如何做到這一點,有人可以幫助我嗎?
在此先感謝!
編輯
爲了解釋我與Shahrooz Jefri和dasblinkenlight提出的解決方案滿足了問題,這裏是一個圖片。左欄是原始數據,沒有過濾,右欄是過濾的數據。兩種方法都提供相同的結果。 紅色是問題所在。
如果路徑到TYPE3 LIEF在2型節點應該發生什麼? – dasblinkenlight 2013-02-08 19:05:26
我必須有完整的路徑,所以它會給類似'type1> type2> ...> type3' – Shimrod 2013-02-08 19:12:19