public void InsertAfterChild (ProjectElement child, ProjectElement reference) { if (reference == null) { PrependChild (child); } else { child.Parent = this; children.AddAfter (reference.LinkedListNode, child.LinkedListNode); } }
public void AppendChild (ProjectElement child) { children.Add (child); child.Parent = this; if (Count != 1) { child.PreviousSibling = children[Count - 2]; children[Count - 2].NextSibling = child; } }
internal static PropertyStorageLocations GetLocationFromCondition(MSBuild.Construction.ProjectElement element) { while (element != null) { if (!string.IsNullOrEmpty(element.Condition)) { return(GetLocationFromCondition(element.Condition)); } element = element.Parent; } return(PropertyStorageLocations.Base); }
public void InsertAfterChild (ProjectElement child, ProjectElement reference) { if (reference == null) { PrependChild (child); } else { child.Parent = this; var referenceIndex = children.IndexOf (reference); children.Insert (referenceIndex + 1, child); child.PreviousSibling = reference; reference.NextSibling = child; if (referenceIndex + 2 < Count) { child.NextSibling = children[referenceIndex + 2]; children[referenceIndex + 2].PreviousSibling = child; } } }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectChooseElement, "OM_CannotAcceptParent"); ErrorUtilities.VerifyThrowInvalidOperation(!(nextSibling is ProjectWhenElement) && !(previousSibling is ProjectOtherwiseElement) && !(nextSibling is ProjectOtherwiseElement), "OM_NoOtherwiseBeforeWhenOrOtherwise"); }
public void RemoveChild (ProjectElement child) { child.Parent = null; children.Remove (child.LinkedListNode); }
public void PrependChild (ProjectElement child) { children.Insert (0, child); child.Parent = this; if (Count != 1) { child.NextSibling = children[1]; children[1].PreviousSibling = child; } }
internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement, "OM_CannotAcceptParent"); }
/// <summary> /// Sets the parent of this element if it is a valid parent, /// otherwise throws. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement || parent is ProjectWhenElement || parent is ProjectOtherwiseElement, "OM_CannotAcceptParent"); int nestingDepth = 0; ProjectElementContainer immediateParent = parent; while (parent != null) { parent = parent.Parent; nestingDepth++; // This should really be an OM error, with no error number. But it's so obscure, it's not worth a new string. ProjectErrorUtilities.VerifyThrowInvalidProject(nestingDepth <= ProjectParser.MaximumChooseNesting, immediateParent.Location, "ChooseOverflow", ProjectParser.MaximumChooseNesting); } }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { VerifyCorrectParent(parent); }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectTargetElement || (Include.Length > 0 || Update.Length > 0 || Remove.Length > 0), "OM_ItemsOutsideTargetMustHaveIncludeOrUpdateOrRemove"); ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectRootElement || parent.Parent is ProjectTargetElement || parent.Parent is ProjectWhenElement || parent.Parent is ProjectOtherwiseElement, "OM_CannotAcceptParent"); }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement || parent is ProjectImportGroupElement, "OM_CannotAcceptParent"); }
/// <summary> /// Sets the parent of this element if it is a valid parent, /// otherwise throws. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectRootElement || parent is ProjectWhenElement || parent is ProjectOtherwiseElement, "OM_CannotAcceptParent"); int nestingDepth = 0; ProjectElementContainer immediateParent = parent; while (parent != null) { parent = parent.Parent; nestingDepth++; // This should really be an OM error, with no error number. But it's so obscure, it's not worth a new string. ProjectErrorUtilities.VerifyThrowInvalidProject(nestingDepth <= ProjectParser.MaximumChooseNesting, immediateParent.Location, "ChooseOverflow", ProjectParser.MaximumChooseNesting); } }
public void RemoveChild(ProjectElement child) { }
private static string CheckNextSibling(ProjectElement nextSibling, int iMaxSiblings) { if (iMaxSiblings > 0) { Microsoft.Build.Construction.ProjectPropertyElement ppe_sibling = (Microsoft.Build.Construction.ProjectPropertyElement)nextSibling; if (ppe_sibling.Name.ToLower().Equals("outputpath")) { return ppe_sibling.Value; } else { if (ppe_sibling.NextSibling!=null) { return CheckNextSibling(ppe_sibling.NextSibling, iMaxSiblings - 1); } else { return null; } } } else { return null; } }
/// <summary> /// Adds a ProjectElement to the Xml tree /// </summary> /// <param name="child">A child to add to the Xml tree, which has already been added to the ProjectElement tree</param> /// <remarks> /// The MSBuild construction APIs keep a tree of ProjectElements and a parallel Xml tree which consists of /// objects from System.Xml. This is a helper method which adds an XmlElement or Xml attribute to the Xml /// tree after the corresponding ProjectElement has been added to the construction API tree, and fixes up /// whitespace as necessary. /// </remarks> internal void AddToXml(ProjectElement child) { if (child.ExpressedAsAttribute) { // todo children represented as attributes need to be placed in order too // Assume that the name of the child has already been validated to conform with rules in XmlUtilities.VerifyThrowArgumentValidElementName // Make sure we're not trying to add multiple attributes with the same name ProjectErrorUtilities.VerifyThrowInvalidProject(!XmlElement.HasAttribute(child.XmlElement.Name), XmlElement.Location, "InvalidChildElementDueToDuplication", child.XmlElement.Name, ElementName); SetElementAsAttributeValue(child); } else { // We want to add the XmlElement to the same position in the child list as the corresponding ProjectElement. // Depending on whether the child ProjectElement has a PreviousSibling or a NextSibling, we may need to // use the InsertAfter, InsertBefore, or AppendChild methods to add it in the right place. // // Also, if PreserveWhitespace is true, then the elements we add won't automatically get indented, so // we try to match the surrounding formatting. // Siblings, in either direction in the linked list, may be represented either as attributes or as elements. // Therefore, we need to traverse both directions to find the first sibling of the same type as the one being added. // If none is found, then the node being added is inserted as the only node of its kind ProjectElement referenceSibling; Predicate <ProjectElement> siblingIsSameAsChild = _ => _.ExpressedAsAttribute == false; if (TrySearchLeftSiblings(child.PreviousSibling, siblingIsSameAsChild, out referenceSibling)) { // Add after previous sibling XmlElement.InsertAfter(child.XmlElement, referenceSibling.XmlElement); if (XmlDocument.PreserveWhitespace) { // Try to match the surrounding formatting by checking the whitespace that precedes the node we inserted // after, and inserting the same whitespace between the previous node and the one we added if (referenceSibling.XmlElement.PreviousSibling != null && referenceSibling.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace) { var newWhitespaceNode = XmlDocument.CreateWhitespace(referenceSibling.XmlElement.PreviousSibling.Value); XmlElement.InsertAfter(newWhitespaceNode, referenceSibling.XmlElement); } } } else if (TrySearchRightSiblings(child.NextSibling, siblingIsSameAsChild, out referenceSibling)) { // Add as first child XmlElement.InsertBefore(child.XmlElement, referenceSibling.XmlElement); if (XmlDocument.PreserveWhitespace) { // Try to match the surrounding formatting by checking the whitespace that precedes where we inserted // the new node, and inserting the same whitespace between the node we added and the one after it. if (child.XmlElement.PreviousSibling != null && child.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace) { var newWhitespaceNode = XmlDocument.CreateWhitespace(child.XmlElement.PreviousSibling.Value); XmlElement.InsertBefore(newWhitespaceNode, referenceSibling.XmlElement); } } } else { // Add as only child XmlElement.AppendChild(child.XmlElement); if (XmlDocument.PreserveWhitespace) { // Try to match the surrounding formatting and add one indentation level if (XmlElement.FirstChild.NodeType == XmlNodeType.Whitespace) { // This container had a whitespace node, which should generally be a newline and the indent // before the closing tag. So we add the default indentation to it so the child will now be indented // further, and then create a new whitespace node after the child so the closing tag will be on // a new line with the same indentation. // If the whitespace we end up copying isn't actually (newline + indentation) like we expect, then it // should still be OK to copy it, as we'll still be trying to match the surrounding formatting. string whitespace = XmlElement.FirstChild.Value; XmlElement.FirstChild.Value = whitespace + DEFAULT_INDENT; var newWhitespaceNode = XmlDocument.CreateWhitespace(whitespace); XmlElement.InsertAfter(newWhitespaceNode, child.XmlElement); } else if (XmlElement.PreviousSibling != null && XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace) { // This container didn't have any whitespace in it. This probably means it didn't have separate open // and close tags. So add a whitespace node before the new child with additional indentation over the // container's indentation, and add a whitespace node with the same level of indentation as the container // after the new child so the closing tag will be indented properly. string parentWhitespace = XmlElement.PreviousSibling.Value; var indentedWhitespaceNode = XmlDocument.CreateWhitespace(parentWhitespace + DEFAULT_INDENT); XmlElement.InsertBefore(indentedWhitespaceNode, child.XmlElement); var unindentedWhitespaceNode = XmlDocument.CreateWhitespace(parentWhitespace); XmlElement.InsertAfter(unindentedWhitespaceNode, child.XmlElement); } } } } }
public void InsertBeforeChild (ProjectElement child, ProjectElement reference) { if (reference == null) { AppendChild (child); } else { child.Parent = this; children.AddBefore (reference.LinkedListNode, child.LinkedListNode); } }
public void AppendChild (ProjectElement child) { children.AddLast (child.LinkedListNode); child.Parent = this; }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal abstract void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer proposedParent, ProjectElement previousSibling, ProjectElement nextSibling);
/// <summary> /// Adds a ProjectElement to the Xml tree /// </summary> /// <param name="child">A child to add to the Xml tree, which has already been added to the ProjectElement tree</param> /// <remarks> /// The MSBuild construction APIs keep a tree of ProjectElements and a parallel Xml tree which consists of /// objects from System.Xml. This is a helper method which adds an XmlElement or Xml attribute to the Xml /// tree after the corresponding ProjectElement has been added to the construction API tree, and fixes up /// whitespace as necessary. /// </remarks> internal void AddToXml(ProjectElement child) { if (child.ExpressedAsAttribute) { // todo children represented as attributes need to be placed in order too // Assume that the name of the child has already been validated to conform with rules in XmlUtilities.VerifyThrowArgumentValidElementName // Make sure we're not trying to add multiple attributes with the same name ProjectErrorUtilities.VerifyThrowInvalidProject(!XmlElement.HasAttribute(child.XmlElement.Name), XmlElement.Location, "InvalidChildElementDueToDuplication", child.XmlElement.Name, ElementName); SetElementAsAttributeValue(child); } else { // We want to add the XmlElement to the same position in the child list as the corresponding ProjectElement. // Depending on whether the child ProjectElement has a PreviousSibling or a NextSibling, we may need to // use the InsertAfter, InsertBefore, or AppendChild methods to add it in the right place. // // Also, if PreserveWhitespace is true, then the elements we add won't automatically get indented, so // we try to match the surrounding formatting. // Siblings, in either direction in the linked list, may be represented either as attributes or as elements. // Therefore, we need to traverse both directions to find the first sibling of the same type as the one being added. // If none is found, then the node being added is inserted as the only node of its kind ProjectElement referenceSibling; Predicate <ProjectElement> siblingIsExplicitElement = _ => _.ExpressedAsAttribute == false; if (TrySearchLeftSiblings(child.PreviousSibling, siblingIsExplicitElement, out referenceSibling)) { // Add after previous sibling XmlElement.InsertAfter(child.XmlElement, referenceSibling.XmlElement); if (XmlDocument.PreserveWhitespace) { // Try to match the surrounding formatting by checking the whitespace that precedes the node we inserted // after, and inserting the same whitespace between the previous node and the one we added if (referenceSibling.XmlElement.PreviousSibling != null && referenceSibling.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace) { var newWhitespaceNode = XmlDocument.CreateWhitespace(referenceSibling.XmlElement.PreviousSibling.Value); XmlElement.InsertAfter(newWhitespaceNode, referenceSibling.XmlElement); } } } else if (TrySearchRightSiblings(child.NextSibling, siblingIsExplicitElement, out referenceSibling)) { // Add as first child XmlElement.InsertBefore(child.XmlElement, referenceSibling.XmlElement); if (XmlDocument.PreserveWhitespace) { // Try to match the surrounding formatting by checking the whitespace that precedes where we inserted // the new node, and inserting the same whitespace between the node we added and the one after it. if (child.XmlElement.PreviousSibling != null && child.XmlElement.PreviousSibling.NodeType == XmlNodeType.Whitespace) { var newWhitespaceNode = XmlDocument.CreateWhitespace(child.XmlElement.PreviousSibling.Value); XmlElement.InsertBefore(newWhitespaceNode, referenceSibling.XmlElement); } } } else { // Add as only child XmlElement.AppendChild(child.XmlElement); if (XmlDocument.PreserveWhitespace) { // If the empty parent has whitespace in it, delete it if (XmlElement.FirstChild.NodeType == XmlNodeType.Whitespace) { XmlElement.RemoveChild(XmlElement.FirstChild); } var parentIndentation = GetElementIndentation(XmlElement); var leadingWhitespaceNode = XmlDocument.CreateWhitespace(Environment.NewLine + parentIndentation + DEFAULT_INDENT); var trailingWhiteSpaceNode = XmlDocument.CreateWhitespace(Environment.NewLine + parentIndentation); XmlElement.InsertBefore(leadingWhitespaceNode, child.XmlElement); XmlElement.InsertAfter(trailingWhiteSpaceNode, child.XmlElement); } } } }
/// <summary> /// Parse a ProjectTargetElement /// </summary> private ProjectTargetElement ParseProjectTargetElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnTarget); ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.name); string targetName = ProjectXmlUtilities.GetAttributeValue(element, XMakeAttributes.name); // Orcas compat: all target names are automatically unescaped targetName = EscapingUtilities.UnescapeAll(targetName); int indexOfSpecialCharacter = targetName.IndexOfAny(XMakeElements.illegalTargetNameCharacters); if (indexOfSpecialCharacter >= 0) { ProjectErrorUtilities.ThrowInvalidProject(element.GetAttributeLocation(XMakeAttributes.name), "NameInvalid", targetName, targetName[indexOfSpecialCharacter]); } ProjectTargetElement target = new ProjectTargetElement(element, _project, _project); ProjectOnErrorElement onError = null; foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; switch (childElement.Name) { case XMakeElements.propertyGroup: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectPropertyGroupElement(childElement, target); break; case XMakeElements.itemGroup: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectItemGroupElement(childElement, target); break; case XMakeElements.onError: onError = ParseProjectOnErrorElement(childElement, target); child = onError; break; case XMakeElements.itemDefinitionGroup: ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ItemDefinitionGroupNotLegalInsideTarget", childElement.Name); break; default: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectTaskElement(childElement, target); break; } target.AppendParentedChildNoChecks(child); } return(target); }
private static bool TrySearchRightSiblings(ProjectElement initialElement, Predicate <ProjectElement> siblingIsAcceptable, out ProjectElement referenceSibling) { return(TrySearchSiblings(initialElement, siblingIsAcceptable, s => s.NextSibling, out referenceSibling)); }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent is ProjectChooseElement, "OM_CannotAcceptParent"); ErrorUtilities.VerifyThrowInvalidOperation(!(previousSibling is ProjectOtherwiseElement), "OM_NoOtherwiseBeforeWhenOrOtherwise"); }
public void RemoveChild(ProjectElement child) { child.Parent = null; children.Remove(child.LinkedListNode); }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { VerifyCorrectParent(parent); }
public void AppendChild(ProjectElement child) { children.AddLast(child.LinkedListNode); child.Parent = this; }
public void RemoveChild (ProjectElement child) { child.Parent = null; children.Remove(child); if (child.NextSibling != null) child.NextSibling.PreviousSibling = child.PreviousSibling; if (child.PreviousSibling != null) child.PreviousSibling.NextSibling = child.NextSibling; }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal abstract void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer proposedParent, ProjectElement previousSibling, ProjectElement nextSibling);
/// <inheritdoc /> public override void CopyFrom(ProjectElement element) { base.CopyFrom(element); // clear out caching fields. _definitelyAreNoChildrenWithWildcards = false; }
/// <summary> /// Dummy required implementation /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.ThrowInternalErrorUnreachable(); }
public void InsertBeforeChild (ProjectElement child, ProjectElement reference) { if (reference == null) { AppendChild (child); } else { child.Parent = this; var referenceIndex = children.IndexOf (reference); children.Insert (referenceIndex, child); child.NextSibling = reference; reference.PreviousSibling = child; if (referenceIndex > 0) { child.PreviousSibling = children[referenceIndex - 1]; children[referenceIndex - 1].NextSibling = child; } } }
/// <inheritdoc /> public override void CopyFrom(ProjectElement element) { base.CopyFrom(element); // clear cached fields _include = null; _exclude = null; _remove = null; _includeHasWildcards = null; }
public void RemoveChild (ProjectElement child) { }
/// <summary> /// Overridden to verify that the potential parent and siblings /// are acceptable. Throws InvalidOperationException if they are not. /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectTargetElement || (Include.Length > 0 || Update.Length > 0 || Remove.Length > 0), "OM_ItemsOutsideTargetMustHaveIncludeOrUpdateOrRemove"); ErrorUtilities.VerifyThrowInvalidOperation(parent.Parent is ProjectRootElement || parent.Parent is ProjectTargetElement || parent.Parent is ProjectWhenElement || parent.Parent is ProjectOtherwiseElement, "OM_CannotAcceptParent"); }
/// <inheritdoc/> public override void CopyFrom(ProjectElement element) { ErrorUtilities.VerifyThrowArgumentNull(element, "element"); ErrorUtilities.VerifyThrowArgument(this.GetType().IsEquivalentTo(element.GetType()), "element"); if (this == element) { return; } this.Label = element.Label; var other = (ProjectExtensionsElement)element; this.Content = other.Content; this.MarkDirty("CopyFrom", null); }
/// <summary> /// Parse the child of a ProjectRootElement /// </summary> private void ParseProjectRootElementChildren(XmlElementWithLocation element) { foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; switch (childElement.Name) { case XMakeElements.propertyGroup: child = ParseProjectPropertyGroupElement(childElement, _project); break; case XMakeElements.itemGroup: child = ParseProjectItemGroupElement(childElement, _project); break; case XMakeElements.importGroup: child = ParseProjectImportGroupElement(childElement, _project); break; case XMakeElements.import: child = ParseProjectImportElement(childElement, _project); break; case XMakeElements.usingTask: child = ParseProjectUsingTaskElement(childElement); break; case XMakeElements.target: child = ParseProjectTargetElement(childElement); break; case XMakeElements.itemDefinitionGroup: child = ParseProjectItemDefinitionGroupElement(childElement); break; case XMakeElements.choose: child = ParseProjectChooseElement(childElement, _project, 0 /* nesting depth */); break; case XMakeElements.projectExtensions: child = ParseProjectExtensionsElement(childElement); break; case XMakeElements.sdk: child = ParseProjectSdkElement(childElement); break; // Obsolete case XMakeElements.error: case XMakeElements.warning: case XMakeElements.message: ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ErrorWarningMessageNotSupported", childElement.Name); break; default: ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, childElement.ParentNode.Name, childElement.Location); break; } _project.AppendParentedChildNoChecks(child); } }
/// <summary> /// Applies properties from the specified type to this instance. /// </summary> /// <param name="element">The element to act as a template to copy from.</param> public virtual void CopyFrom(ProjectElement element) { ErrorUtilities.VerifyThrowArgumentNull(element, "element"); ErrorUtilities.VerifyThrowArgument(this.GetType().IsEquivalentTo(element.GetType()), "element"); if (this == element) { return; } // Remove all the current attributes and textual content. this.XmlElement.RemoveAllAttributes(); if (this.XmlElement.ChildNodes.Count == 1 && this.XmlElement.FirstChild.NodeType == XmlNodeType.Text) { this.XmlElement.RemoveChild(this.XmlElement.FirstChild); } // Ensure the element name itself matches. this.ReplaceElement(XmlUtilities.RenameXmlElement(this.XmlElement, element.XmlElement.Name, XmlElement.NamespaceURI)); // Copy over the attributes from the template element. foreach (XmlAttribute attribute in element.XmlElement.Attributes) { this.XmlElement.SetAttribute(attribute.LocalName, attribute.NamespaceURI, attribute.Value); } // If this element has pure text content, copy that over. if (element.XmlElement.ChildNodes.Count == 1 && element.XmlElement.FirstChild.NodeType == XmlNodeType.Text) { this.XmlElement.AppendChild(this.XmlElement.OwnerDocument.CreateTextNode(element.XmlElement.FirstChild.Value)); } this._expressedAsAttribute = element._expressedAsAttribute; this.MarkDirty("CopyFrom", null); }
/// <summary> /// Parse a ProjectUsingTaskElement /// </summary> private ProjectUsingTaskElement ParseProjectUsingTaskElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnUsingTask); ProjectErrorUtilities.VerifyThrowInvalidProject(element.GetAttribute(XMakeAttributes.taskName).Length > 0, element.Location, "ProjectTaskNameEmpty"); string assemblyName = element.GetAttribute(XMakeAttributes.assemblyName); string assemblyFile = element.GetAttribute(XMakeAttributes.assemblyFile); ProjectErrorUtilities.VerifyThrowInvalidProject ( ((assemblyName.Length > 0) ^ (assemblyFile.Length > 0)), element.Location, "UsingTaskAssemblySpecification", XMakeElements.usingTask, XMakeAttributes.assemblyName, XMakeAttributes.assemblyFile ); ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyName); ProjectXmlUtilities.VerifyThrowProjectAttributeEitherMissingOrNotEmpty(element, XMakeAttributes.assemblyFile); ProjectUsingTaskElement usingTask = new ProjectUsingTaskElement(element, _project, _project); bool foundTaskElement = false; bool foundParameterGroup = false; foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; string childElementName = childElement.Name; switch (childElementName) { case XMakeElements.usingTaskParameterGroup: if (foundParameterGroup) { ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement); } child = ParseUsingTaskParameterGroupElement(childElement, usingTask); foundParameterGroup = true; break; case XMakeElements.usingTaskBody: if (foundTaskElement) { ProjectXmlUtilities.ThrowProjectInvalidChildElementDueToDuplicate(childElement); } child = ParseUsingTaskBodyElement(childElement, usingTask); foundTaskElement = true; break; default: ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, element.Name, element.Location); break; } usingTask.AppendParentedChildNoChecks(child); } return(usingTask); }
/// <summary> /// Dummy required implementation /// </summary> internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling) { ErrorUtilities.ThrowInternalErrorUnreachable(); }
/// <inheritdoc /> public override void CopyFrom(ProjectElement element) { base.CopyFrom(element); // Clear caching fields _name = null; }