ユニットと呼ばれるac#クラスをマップするにはどうすればよいですかList<Unit>
。
具体的なシナリオは、第1レベルの子であるリストを含むrootUnitオブジェクトです。
第1レベルの子ユニットオブジェクトには他のユニットが含まれないため、階層に再帰はありません。
public class Unit
{
public Unit()
{
// Explicitly set the default value for the first unit in a hierarchy
HierarchyIndex = 0;
Units = new List<Unit>();
}
public List<Unit> Units { get; set; }
public int UnitId { get; set; }
public string Name { get; set; }
public Nullable<int> ParentId { get; set; }
public int TemplateId { get; set; }
public bool HasChildren { get; set; }
public bool IsFolder { get; set; }
public DateTime CreatedAt { get; set; }
public int HierarchyIndex { get; set; }
}
上記のユニットをこのビューモデルにマップします。
public class UnitTreeViewModel
{
[JsonProperty("key")]
public int UnitId { get; set; }
[JsonProperty("title")]
public string Name { get; set; }
[JsonProperty("isLazy")]
public bool HasChildren { get; set; }
[JsonProperty("isFolder")]
public bool IsFolder { get; set; }
}