本文整理汇总了C#中Microsoft.Build.Construction.XmlElementWithLocation.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElementWithLocation.HasAttribute方法的具体用法?C# XmlElementWithLocation.HasAttribute怎么用?C# XmlElementWithLocation.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Construction.XmlElementWithLocation
的用法示例。
在下文中一共展示了XmlElementWithLocation.HasAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseProjectItemElement
/// <summary>
/// Parse a ProjectItemElement
/// </summary>
private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
{
ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnItem);
bool belowTarget = parent.Parent is ProjectTargetElement;
string itemType = element.Name;
string include = element.GetAttribute(XMakeAttributes.include);
string exclude = element.GetAttribute(XMakeAttributes.exclude);
string remove = element.GetAttribute(XMakeAttributes.remove);
string update = element.GetAttribute(XMakeAttributes.update);
var exclusiveItemOperation = "";
int exclusiveAttributeCount = 0;
if (element.HasAttribute(XMakeAttributes.include))
{
exclusiveAttributeCount++;
exclusiveItemOperation = XMakeAttributes.include;
}
if (element.HasAttribute(XMakeAttributes.remove))
{
exclusiveAttributeCount++;
exclusiveItemOperation = XMakeAttributes.remove;
}
if (element.HasAttribute(XMakeAttributes.update))
{
exclusiveAttributeCount++;
exclusiveItemOperation = XMakeAttributes.update;
}
// At most one of the include, remove, or update attributes may be specified
if (exclusiveAttributeCount > 1)
{
XmlAttributeWithLocation errorAttribute = remove.Length > 0 ? (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove] : (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.update];
ProjectErrorUtilities.ThrowInvalidProject(errorAttribute.Location, "InvalidAttributeExclusive");
}
// Include, remove, or update must be present unless inside a target
ProjectErrorUtilities.VerifyThrowInvalidProject(exclusiveAttributeCount == 1 || belowTarget, element.Location, "MissingRequiredAttribute", exclusiveItemOperation, itemType);
// Exclude must be missing, unless Include exists
ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]);
// If we have an Include attribute at all, it must have non-zero length
ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType);
// If we have a Remove attribute at all, it must have non-zero length
ProjectErrorUtilities.VerifyThrowInvalidProject(remove.Length > 0 || element.Attributes[XMakeAttributes.remove] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.remove, itemType);
// If we have an Update attribute at all, it must have non-zero length
ProjectErrorUtilities.VerifyThrowInvalidProject(update.Length > 0 || element.Attributes[XMakeAttributes.update] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.update, itemType);
XmlUtilities.VerifyThrowProjectValidElementName(element);
ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType);
ProjectItemElement item = new ProjectItemElement(element, parent, _project);
foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
{
ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item);
item.AppendParentedChildNoChecks(metadatum);
}
return item;
}