下面给出的是我的类结构,我正在尝试构建一个可以存储并且可以访问下面给出的数据层次结构的类。
用文字总结(请参见代码后的层次结构);
所有区域只有 1 个主区域
在一个区域下可以有一个或多个位置。
public class RegionLocItemView
{
public Guid Id { get; set; }
public string name { get; set; }
public Guid value { get; set; }
public bool isChecked { get; set; }
public List<RegionLocItemView> Children
{
get ;
set
{
//where do i set this from
} ;
}
public RegionLocItemView(List<RegionLocItemView> a)
{
Children = a;
}
public RegionLocItemView()
{
}
} /// end of class
Accessing class from code below:
var getAvailableLocations = Model.SessionProvider.GetAvailableLocations.Where(e => e.Location.Count >= 1);
Guid parentid = Guid.Empty;
RegionLocItemView cls = new RegionLocItemView();
List<RegionLocItemView> main = new List<RegionLocItemView>();
foreach (var a in getAvailableLocations)
{
if (a.ParentID == null)
{
//found Parent of all regions.
//cls = new RegionLocItemView();
cls.Id = a.ID;
parentid = a.ID;
cls.name = a.RecordName;
//main.Add(cls);
// break;
}
if (a.ParentID == parentid)
{
RegionLocItemView cls1 = new RegionLocItemView();
//found children
cls1.Id = a.ID;
parentid = a.ID;
cls1.name = a.RecordName;
cls.Children.Add(new List<RegionLocItemView>(cls1));
}
}
我需要一个 IEnumerable 集合列表来存储下面层次结构中的对象。
Main
Region1
Location1
Location2
Location3
Region2
LocationA
LocationB
LocationC
Region...
Location...
问题:
您能否针对上面的数据重构我上面的类结构,并为我提供如何在 C# 代码中访问该类的代码示例。我正在从 IEnumerable 集合中读取上述数据,并且数据排列不正确,因此我需要执行上述操作。
为什么我想要这个类结构:我想要这个以便我可以将它绑定到一个 Telerik TreView 控件,该控件接受一个 IEnumerable 集合,如一个通用列表。