lundi 26 juillet 2021

c# Enumerate List to map parentId's from a folder structure

I have a List that contains this class:

public class RazorTree
{
    public int id { get; set; }
    public string Name { get; set; }        
    public string Path { get; set; }
    public int? parentId { get; set; } = null;
}

Example:

id = 1
path = "C:\\Projects\\testapp\subdirectoy\\"
name = "root"
parentId = null

id = 45
path = "C:\\Projects\\testapp\subdirectoy\\test.razor"
name = "test"
parentId = null

id = 55
path = "C:\\Projects\\testapp\subdirectoy\\subdirectory2\\test.razor"
name = "test"
parentId = null

What i need is that the entry with id = 45 should have parentId = 1 and id = 55 should have parentId = 45 depending on the path that each entry has.

How can i link the children with their respective parent based on the path each one has?

enter image description here





Aucun commentaire:

Enregistrer un commentaire