27 lines
689 B
C#
27 lines
689 B
C#
|
namespace InnovEnergy.API.DataModel;
|
||
|
|
||
|
public static class DataExtensions
|
||
|
{
|
||
|
public static Folder GetOrCreateFolder(this Data data, IEnumerable<String> path)
|
||
|
{
|
||
|
var parent = data.Root;
|
||
|
var stack = new Stack<String>(path.Reverse());
|
||
|
|
||
|
while (stack.Count > 0)
|
||
|
{
|
||
|
var childFolderName = stack.Pop();
|
||
|
|
||
|
var childFolder = parent.Folders.FirstOrDefault(f => f.Name == childFolderName);
|
||
|
|
||
|
if (childFolder is null)
|
||
|
{
|
||
|
childFolder = new Folder { Name = childFolderName };
|
||
|
parent.Add(childFolder);
|
||
|
}
|
||
|
|
||
|
parent = childFolder;
|
||
|
}
|
||
|
|
||
|
return parent;
|
||
|
}
|
||
|
}
|