public void SetProjectExtension(XmlElement value) { AssertCanModify(); var sr = new StringReader(value.OuterXml); var xr = new XmlTextReader(sr); xr.MoveToContent(); var cr = new MSBuildXmlReader { XmlReader = xr }; var section = value.LocalName; MSBuildXmlElement elem = new MSBuildXmlElement(); elem.Read(cr); int i = ChildNodes.FindIndex(n => (n is MSBuildXmlElement) && ((MSBuildXmlElement)n).Name == section); if (i == -1) { ChildNodes = ChildNodes.Add(elem); } else { ChildNodes = ChildNodes.RemoveAt(i); ChildNodes = ChildNodes.Insert(i, elem); } elem.ParentNode = this; elem.ResetIndent(false); NotifyChanged(); }
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 void RemoveProjectExtension(string section) { AssertCanModify(); int i = ChildNodes.FindIndex(n => (n is MSBuildXmlElement) && ((MSBuildXmlElement)n).Name == section); if (i != -1) { ChildNodes = ChildNodes.RemoveAt(i); NotifyChanged(); } }
internal void CopyFrom(MSBuildPropertyGroup other) { AssertCanModify(); foreach (var node in other.ChildNodes) { var prop = node as MSBuildProperty; if (prop != null) { var cp = prop.Clone(); var currentPropIndex = ChildNodes.FindIndex(p => (p is MSBuildProperty) && ((MSBuildProperty)p).Name == prop.Name); if (currentPropIndex != -1) { var currentProp = (MSBuildProperty)ChildNodes [currentPropIndex]; ChildNodes = ChildNodes.SetItem(currentPropIndex, cp); } else { ChildNodes = ChildNodes.Add(cp); } properties [cp.Name] = cp; cp.ParentNode = PropertiesParent; cp.Owner = this; cp.ResetIndent(false); } else { ChildNodes = ChildNodes.Add(node); } } foreach (var prop in ChildNodes.OfType <MSBuildProperty> ().ToArray()) { if (!other.HasProperty(prop.Name)) { RemoveProperty(prop); } } NotifyChanged(); }