public void AddPropertyGroup(MSBuildPropertyGroup group, bool insertAtEnd = true, MSBuildObject beforeObject = null) { AssertCanModify(); if (group.ParentProject != null) { throw new InvalidOperationException("Group already belongs to a project"); } group.ParentNode = this; bool added = false; if (beforeObject != null) { var index = ChildNodes.IndexOf(beforeObject); if (index != -1) { ChildNodes = ChildNodes.Insert(index, group); added = true; } } if (!added) { if (insertAtEnd) { var last = ChildNodes.FindLastIndex(g => g is MSBuildPropertyGroup); if (last != -1) { ChildNodes = ChildNodes.Insert(last + 1, group); added = true; } } else { var first = ChildNodes.FindIndex(g => g is MSBuildPropertyGroup); if (first != -1) { ChildNodes = ChildNodes.Insert(first, group); added = true; } } if (!added) { var first = ChildNodes.FindIndex(g => g is MSBuildItemGroup); if (first != -1) { ChildNodes = ChildNodes.Insert(first, group); } else { ChildNodes = ChildNodes.Add(group); } } } group.ResetIndent(true); NotifyChanged(); }
public MSBuildImport AddNewImport(string name, string condition = null, MSBuildObject beforeObject = null) { AssertCanModify(); var import = new MSBuildImport { Project = name, Condition = condition }; int index = -1; if (beforeObject != null) { index = ChildNodes.IndexOf(beforeObject); } else { index = ChildNodes.FindLastIndex(ob => ob is MSBuildImport); if (index != -1) { index++; } } import.ParentNode = this; if (index != -1) { ChildNodes = ChildNodes.Insert(index, import); } else { ChildNodes = ChildNodes.Add(import); } import.ResetIndent(false); NotifyChanged(); return(import); }