當前位置: 首頁>>代碼示例>>C#>>正文


C# Construction.XmlElementWithLocation類代碼示例

本文整理匯總了C#中Microsoft.Build.Construction.XmlElementWithLocation的典型用法代碼示例。如果您正苦於以下問題:C# XmlElementWithLocation類的具體用法?C# XmlElementWithLocation怎麽用?C# XmlElementWithLocation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XmlElementWithLocation類屬於Microsoft.Build.Construction命名空間,在下文中一共展示了XmlElementWithLocation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RenameXmlElement

        /// <summary>
        /// This method renames an XML element.  Well, actually you can't directly
        /// rename an XML element using the DOM, so what you have to do is create
        /// a brand new XML element with the new name, and copy over all the attributes
        /// and children.  This method returns the new XML element object.
        /// If the name is the same, does nothing and returns the element passed in.
        /// </summary>
        /// <param name="oldElement"></param>
        /// <param name="newElementName"></param>
        /// <param name="xmlNamespace">Can be null if global namespace.</param>
        /// <returns>new/renamed element</returns>
        internal static XmlElementWithLocation RenameXmlElement(XmlElementWithLocation oldElement, string newElementName, string xmlNamespace)
        {
            if (String.Equals(oldElement.Name, newElementName, StringComparison.Ordinal) && String.Equals(oldElement.NamespaceURI, xmlNamespace, StringComparison.Ordinal))
            {
                return oldElement;
            }

            XmlElementWithLocation newElement = (xmlNamespace == null)
                ? (XmlElementWithLocation)oldElement.OwnerDocument.CreateElement(newElementName)
                : (XmlElementWithLocation)oldElement.OwnerDocument.CreateElement(newElementName, xmlNamespace);

            // Copy over all the attributes.
            foreach (XmlAttribute oldAttribute in oldElement.Attributes)
            {
                XmlAttribute newAttribute = (XmlAttribute)oldAttribute.CloneNode(true);
                newElement.SetAttributeNode(newAttribute);
            }

            // Move over all the child nodes - no need to change their identity
            while (oldElement.HasChildNodes)
            {
                // This conveniently updates FirstChild and HasChildNodes on oldElement.
                newElement.AppendChild(oldElement.FirstChild);
            }

            if (oldElement.ParentNode != null)
            {
                // Add the new element in the same place the old element was.
                oldElement.ParentNode.ReplaceChild(newElement, oldElement);
            }

            return newElement;
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:44,代碼來源:XmlUtilities.cs

示例2: GetChildElements

        /// <summary>
        /// Gets child elements, ignoring whitespace and comments.
        /// Verifies xml namespace of elements is the MSBuild namespace.
        /// Throws InvalidProjectFileException for elements in the wrong namespace, and (if parameter is set) unexpected XML node types
        /// </summary>
        private static List<XmlElementWithLocation> GetChildElements(XmlElementWithLocation element, bool throwForInvalidNodeTypes)
        {
            List<XmlElementWithLocation> children = new List<XmlElementWithLocation>();

            foreach (XmlNode child in element)
            {
                switch (child.NodeType)
                {
                    case XmlNodeType.Comment:
                    case XmlNodeType.Whitespace:
                        // These are legal, and ignored
                        break;

                    case XmlNodeType.Element:
                        XmlElementWithLocation childElement = (XmlElementWithLocation)child;
                        VerifyThrowProjectValidNamespace(childElement);
                        children.Add(childElement);
                        break;

                    default:
                        if (throwForInvalidNodeTypes)
                        {
                            ThrowProjectInvalidChildElement(child.Name, element.Name, element.Location);
                        }
                        break;
                }
            }
            return children;
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:34,代碼來源:ProjectXmlUtilities.cs

示例3: VerifyThrowProjectNoChildElements

 /// <summary>
 /// Throw an invalid project exception if there are any child elements at all
 /// </summary>
 internal static void VerifyThrowProjectNoChildElements(XmlElementWithLocation element)
 {
     List<XmlElementWithLocation> childElements = GetVerifyThrowProjectChildElements(element);
     if (childElements.Count > 0)
     {
         ThrowProjectInvalidChildElement(element.FirstChild.Name, element.Name, element.Location);
     }
 }
開發者ID:cdmihai,項目名稱:msbuild,代碼行數:11,代碼來源:ProjectXmlUtilities.cs

示例4: GetChildElements

        /// <summary>
        /// Gets child elements, ignoring whitespace and comments.
        /// Verifies xml namespace of elements is the MSBuild namespace.
        /// Throws InvalidProjectFileException for elements in the wrong namespace, and (if parameter is set) unexpected XML node types
        /// </summary>
        private static List<XmlElementWithLocation> GetChildElements(XmlElementWithLocation element, bool throwForInvalidNodeTypes)
        {
            List<XmlElementWithLocation> children = new List<XmlElementWithLocation>();

            foreach (XmlNode child in element)
            {
                switch (child.NodeType)
                {
                    case XmlNodeType.Comment:
                    case XmlNodeType.Whitespace:
                        // These are legal, and ignored
                        break;

                    case XmlNodeType.Element:
                        XmlElementWithLocation childElement = (XmlElementWithLocation)child;
                        VerifyThrowProjectValidNamespace(childElement);
                        children.Add(childElement);
                        break;

                    default:
                        if (child.NodeType == XmlNodeType.Text && String.IsNullOrWhiteSpace(child.InnerText))
                        {
                            // If the text is greather than 4k and only contains whitespace, the XML reader will assume it's a text node
                            // instead of ignoring it.  Our call to String.IsNullOrWhiteSpace() can be a little slow if the text is
                            // large but this should be extremely rare.
                            break;
                        }
                        if (throwForInvalidNodeTypes)
                        {
                            ThrowProjectInvalidChildElement(child.Name, element.Name, element.Location);
                        }
                        break;
                }
            }
            return children;
        }
開發者ID:cdmihai,項目名稱:msbuild,代碼行數:41,代碼來源:ProjectXmlUtilities.cs

示例5: SetProjectRootElementFromParser

 /// <summary>
 /// Called only by the parser to tell the ProjectRootElement its backing XmlElement and its own parent project (itself)
 /// This can't be done during construction, as it hasn't loaded the document at that point and it doesn't have a 'this' pointer either.
 /// </summary>
 internal void SetProjectRootElementFromParser(XmlElementWithLocation xmlElement, ProjectRootElement projectRootElement)
 {
     this.XmlElement = xmlElement;
     this.ContainingProject = projectRootElement;
 }
開發者ID:cdmihai,項目名稱:msbuild,代碼行數:9,代碼來源:ProjectElement.cs

示例6: ParseWhenOtherwiseChildren

        /// <summary>
        /// Parse the children of a When or Otherwise
        /// </summary>
        private void ParseWhenOtherwiseChildren(XmlElementWithLocation element, ProjectElementContainer parent, int nestingDepth)
        {
            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectElement child = null;

                switch (childElement.Name)
                {
                    case XMakeElements.propertyGroup:
                        child = ParseProjectPropertyGroupElement(childElement, parent);
                        break;

                    case XMakeElements.itemGroup:
                        child = ParseProjectItemGroupElement(childElement, parent);
                        break;

                    case XMakeElements.choose:
                        child = ParseProjectChooseElement(childElement, parent, nestingDepth);
                        break;

                    default:
                        ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement.Name, element.Name, element.Location);
                        break;
                }

                parent.AppendParentedChildNoChecks(child);
            }
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:31,代碼來源:ProjectParser.cs

示例7: ParseProjectWhenElement

        /// <summary>
        /// Parse a ProjectWhenElement
        /// </summary>
        private ProjectWhenElement ParseProjectWhenElement(XmlElementWithLocation element, ProjectChooseElement parent, int nestingDepth)
        {
            ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.condition);

            ProjectWhenElement when = new ProjectWhenElement(element, parent, _project);

            ParseWhenOtherwiseChildren(element, when, nestingDepth);

            return when;
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:13,代碼來源:ProjectParser.cs

示例8: ParseProjectItemDefinitionXml

        /// <summary>
        /// Pasre a ProjectItemDefinitionElement
        /// </summary>
        private ProjectItemDefinitionElement ParseProjectItemDefinitionXml(XmlElementWithLocation element, ProjectItemDefinitionGroupElement parent)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel);

            // Orcas inadvertently did not check for reserved item types (like "Choose") in item definitions,
            // as we do for item types in item groups. So we do not have a check here.
            // Although we could perhaps add one, as such item definitions couldn't be used 
            // since no items can have the reserved itemType.
            ProjectItemDefinitionElement itemDefinition = new ProjectItemDefinitionElement(element, parent, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, itemDefinition);

                itemDefinition.AppendParentedChildNoChecks(metadatum);
            }

            return itemDefinition;
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:22,代碼來源:ProjectParser.cs

示例9: ParseProjectOnErrorElement

        /// <summary>
        /// Parse a ProjectOnErrorElement
        /// </summary>
        private ProjectOnErrorElement ParseProjectOnErrorElement(XmlElementWithLocation element, ProjectTargetElement parent)
        {
            // Previous OM accidentally didn't verify ExecuteTargets on parse,
            // but we do, as it makes no sense 
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnOnError);
            ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.executeTargets);
            ProjectXmlUtilities.VerifyThrowProjectNoChildElements(element);

            return new ProjectOnErrorElement(element, parent, _project);
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:13,代碼來源:ProjectParser.cs

示例10: ParseProjectTaskElement

        /// <summary>
        /// Parse a ProjectTaskElement
        /// </summary>
        private ProjectTaskElement ParseProjectTaskElement(XmlElementWithLocation element, ProjectTargetElement parent)
        {
            foreach (XmlAttributeWithLocation attribute in element.Attributes)
            {
                ProjectErrorUtilities.VerifyThrowInvalidProject
                (
                !XMakeAttributes.IsBadlyCasedSpecialTaskAttribute(attribute.Name),
                attribute.Location,
                "BadlyCasedSpecialTaskAttribute",
                attribute.Name,
                element.Name,
                element.Name
                );
            }

            ProjectTaskElement task = new ProjectTaskElement(element, parent, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectErrorUtilities.VerifyThrowInvalidProject(childElement.Name == XMakeElements.output, childElement.Location, "UnrecognizedChildElement", childElement.Name, task.Name);

                ProjectOutputElement output = ParseProjectOutputElement(childElement, task);

                task.AppendParentedChildNoChecks(output);
            }

            return task;
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:31,代碼來源:ProjectParser.cs

示例11: ParseProjectPropertyGroupElement

        /// <summary>
        /// Parse a ProjectPropertyGroupElement from the element
        /// </summary>
        private ProjectPropertyGroupElement ParseProjectPropertyGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel);

            ProjectPropertyGroupElement propertyGroup = new ProjectPropertyGroupElement(element, parent, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectPropertyElement property = ParseProjectPropertyElement(childElement, propertyGroup);

                propertyGroup.AppendParentedChildNoChecks(property);
            }

            return propertyGroup;
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:18,代碼來源:ProjectParser.cs

示例12: ParseProjectRootElementChildren

        /// <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;

                    // 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);
            }
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:62,代碼來源:ProjectParser.cs

示例13: ParseProjectElement

        /// <summary>
        /// Parse a ProjectRootElement from an element
        /// </summary>
        private void ParseProjectElement(XmlElementWithLocation element)
        {
            // Historically, we allow any attribute on the Project element

            // The element wasn't available to the ProjectRootElement constructor,
            // so we have to set it now
            _project.SetProjectRootElementFromParser(element, _project);

            ParseProjectRootElementChildren(element);
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:13,代碼來源:ProjectParser.cs

示例14: ProjectImportElement

 /// <summary>
 /// Initialize an unparented ProjectImportElement
 /// </summary>
 private ProjectImportElement(XmlElementWithLocation xmlElement, ProjectRootElement containingProject)
     : base(xmlElement, null, containingProject)
 {
 }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:7,代碼來源:ProjectImportElement.cs

示例15: ParseProjectUsingTaskElement

        /// <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;
        }
開發者ID:nikson,項目名稱:msbuild,代碼行數:63,代碼來源:ProjectParser.cs


注:本文中的Microsoft.Build.Construction.XmlElementWithLocation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。