本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例14: ProjectImportElement
/// <summary>
/// Initialize an unparented ProjectImportElement
/// </summary>
private ProjectImportElement(XmlElementWithLocation xmlElement, ProjectRootElement containingProject)
: base(xmlElement, null, containingProject)
{
}
示例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;
}