Wednesday, 7 August 2019

(ID/ParentID) list to Hierarchical list


 public List<AppInfo> GetTotalAppsInfo()
        {
Action<classname> SetChildren = null;
                //Initialize the hierarchical list to root level items
                List<classname> hierarchicalItems = all
                    .Where(rootItem => rootItem.ParentId == 0)
                    .ToList();

                SetChildren = parent =>
                                {
                                    parent.ChildItems = all
                                    .Where(childItem => childItem.ParentId == parent.Id)
                                        .ToList();

                                    //Recursively call the SetChildren method for each child.
                                    parent.ChildItems
                                            .ForEach(SetChildren);
                                };

                //Call the SetChildren method to set the children on each root level item.
                hierarchicalItems.ForEach(SetChildren);
                return hierarchicalItems;
}

No comments:

Post a Comment

Extracting Nupkg files using command line

Rename it to zip first then extract files as below 1.     Rename-Item -Path A_Package.nupkg -NewName A_Package.zip 2.     Make sure to repla...