private static SourceItemDefinition CreateFoldersOnPath(string path, RootFolderDefinition rootFolder) { SourceItemDefinition folder = rootFolder; while (path.Contains('/')) { var index = path.IndexOf('/'); string folderName = path.Substring(0, path.IndexOf('/')); var existingFolder = folder.Children.FirstOrDefault(c => c.Name == folderName); if (existingFolder != null) { folder = existingFolder; } else { var newFolder = new FolderDefinition(folderName) { Parent = folder }; folder.Children.Add(newFolder); folder = newFolder; } path = path.Substring(index + 1); } return(folder); }
public static void Replace(SourceItemDefinition replace, SourceItemDefinition with) { if (replace.GetType() != with.GetType()) { throw new InvalidOperationException(); } with.Parent = replace.Parent; foreach (SourceItemDefinition child in replace.Children) { with.AddChild(child); } replace.Parent = null; replace.Children.Clear(); // TODO: replace references in model nodes }
public virtual void AddChild(SourceItemDefinition child) { child.Parent = this; Children.Add(child); }