当前位置: 首页>>代码示例>>C#>>正文


C# this.Attributes方法代码示例

本文整理汇总了C#中this.Attributes方法的典型用法代码示例。如果您正苦于以下问题:C# this.Attributes方法的具体用法?C# this.Attributes怎么用?C# this.Attributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.Attributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Attributes

 public static IEnumerable<XAttribute> Attributes(this IEnumerable<XElement> elements, XName name, bool ignoreNamespace)
 {
     if (ignoreNamespace)
         return elements.Attributes().Where(a => a.Name.LocalName == name.LocalName);
     else
         return elements.Attributes(name);
 }
开发者ID:ninja2003,项目名称:duality,代码行数:7,代码来源:ExtMethodsXml.cs

示例2: GenerateXPathFromXElement

        public static string GenerateXPathFromXElement(this XElement xUi)
        {
            var original = xUi.GetAttributeValue("XPath");
            if (!String.IsNullOrEmpty(original))
                return original;
            var tag = "//*";
            var xTag = xUi.Attribute("tag");
            var xType = xUi.Attribute("type");
            if (xType != null)
            {
                if (xType.Value.Equals("a"))
                {
                    tag = "//a";
                    xType.Remove();
                }
                if(xType.Value.Equals("table")||xType.Value.Equals("div"))
                {
                    var textAttr = xUi.Attribute("text");
                    if(textAttr!=null) textAttr.Remove();
                }

            }
            if (xTag != null)
            {
                tag = "//" + xTag.Value;
                xTag.Remove();
            }
            var xpath = tag;
            if (xUi.Attributes().Any())
            {
                xpath = xpath + "[";
                var count = 0;
                foreach (XAttribute xa in xUi.Attributes())
                {
                    var key = xa.Name.ToString();
                    if (key.StartsWith("_"))
                        continue;
                    var value = xa.Value;
                    if (count > 0)
                        xpath = xpath + " and ";
                    if (key.Equals("text"))
                    {
                        if (value.Length < 32)
                            xpath = xpath + key + "()='" + value + "' ";
                        else
                        {
                            xpath = xpath + "contains(text(),'" + value.Substring(0, 16) + "') ";
                        }
                    }

                    else
                        xpath = xpath + "@" + key + "='" + value + "' ";
                    count++;
                }
                xpath = xpath + "]";
            }
            return xpath;
        }
开发者ID:bperreault,项目名称:autox,代码行数:58,代码来源:XElementExt.cs

示例3: GetSize

 internal static Size GetSize(this XElement e)
 {
     var wAttr = e.Attributes().FirstOrDefault(a => a.Name.LocalName.ToLower() == "width");
     var hAttr = e.Attributes().FirstOrDefault(a => a.Name.LocalName.ToLower() == "height");
     var w = wAttr != null ? wAttr.Value : "0";
     var h = hAttr != null ? hAttr.Value : "0";
     var Size = new Size(int.Parse(w), int.Parse(h));
     return Size;
 }
开发者ID:TA-Gen,项目名称:TA-Gen,代码行数:9,代码来源:XElementExtensions.cs

示例4: GetLocation

 internal static Point GetLocation(this XElement e)
 {
     var xAttr = e.Attributes().FirstOrDefault(a => a.Name.LocalName.ToLower() == "x");
     var yAttr = e.Attributes().FirstOrDefault(a => a.Name.LocalName.ToLower() == "y");
     var x = xAttr != null ? xAttr.Value : "0";
     var y = yAttr != null ? yAttr.Value : "0";
     var Location = new Point(int.Parse(x), int.Parse(y));
     return Location;
 }
开发者ID:TA-Gen,项目名称:TA-Gen,代码行数:9,代码来源:XElementExtensions.cs

示例5: GetAttributeValue

 public static string GetAttributeValue(this XElement element, string attributeName)
 {
     string result = null;
     if (element.HasAttributes && element.Attributes().Any(x => x.Name.LocalName == attributeName))
     {
         result = element.Attributes().First(x => x.Name.LocalName == attributeName).Value;
     }
     return result;
 }
开发者ID:bowes282,项目名称:ServiceStackVS,代码行数:9,代码来源:ExternalTemplateWizard.cs

示例6: Attributes

 /// <summary>
 /// Returns a filtered collection of the attributes of every element in the source
 /// collection. Only elements that have a matching <see cref="System.Xml.Linq.XName"/> are
 /// included in the collection.
 /// </summary>
 /// <param name="elements"></param>
 /// <param name="name"></param>
 /// <param name="ignoreCase"></param>
 /// <returns></returns>
 public static IEnumerable<XAttribute> Attributes( this IEnumerable<XElement> elements, XName name, bool ignoreCase )
 {
     if ( ignoreCase )
     {
         return elements.Attributes().Where( p => p.Name.ToString().ToLower() == name.ToString().ToLower() );
     }
     else
     {
         return elements.Attributes( name );
     }
 }
开发者ID:Glazed,项目名称:Dredmor-XML-Validator,代码行数:20,代码来源:XmlExtensions.cs

示例7: RemoveAllNamespaces

 internal static XElement RemoveAllNamespaces(this XElement e)
 {
     return new XElement(e.Name.LocalName,
         (from n in e.Nodes()
             select ((n is XElement) ? RemoveAllNamespaces(n as XElement) : n)),
         (e.HasAttributes) ?
             (from a in e.Attributes()
                 where (!a.IsNamespaceDeclaration)
                       && (a.Name.NamespaceName == "" // Doesn't check primary attribute
                           || e.Attributes().All(x => x == a || a.Name.LocalName != x.Name.LocalName))
                 select new XAttribute(a.Name.LocalName, a.Value)) : null);
 }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:12,代码来源:XElement.RemoveAllNamespaces.cs

示例8: GetClassName

        public static string GetClassName(this XElement element)
        {
            XNamespace ns = "http://www.w3.org/1999/xhtml";
              var noClass = element.Attributes().All(a => a.Name != (ns + "class"));

              return noClass ? string.Empty : element.Attribute("class").Value;
        }
开发者ID:garmstrong11,项目名称:RFQBuddy,代码行数:7,代码来源:Extensions.cs

示例9: AttributeIgnoreCase

 /// <summary>
 /// Returns a filtered collection of attributes of this element. Only elements
 ///     that have a matching System.Xml.Linq.XName are included in the collection, ignoring case.
 /// </summary>
 /// <param name="element">The class being extended.</param>
 /// <param name="name">The name of the attribute</param>
 /// <returns>XAttribute</returns>
 public static XAttribute AttributeIgnoreCase(this XElement element, XName name)
 {
     return
         element.Attributes()
             .FirstOrDefault(
                 s => string.Equals(s.Name.LocalName, name.LocalName, StringComparison.OrdinalIgnoreCase));
 }
开发者ID:MetalKid,项目名称:ThatConference-Aurelia,代码行数:14,代码来源:LinqToXmlExtensions.cs

示例10: ToValues

 public static IDictionary<string, object> ToValues(this XElement element)
 {
     var values = new Dictionary<string, object>();
     foreach (var attribute in element.Attributes())
         values[attribute.Name.ToString()] = attribute.Value;
     return values;
 }
开发者ID:baralong,项目名称:forklift,代码行数:7,代码来源:Extensions.cs

示例11: Except

        // REVIEW: We can use a stack if the perf is bad for Except and MergeWith
        public static XElement Except(this XElement source, XElement target)
        {
            if (target == null)
            {
                return source;
            }

            IEnumerable<XAttribute> attributesToRemove = from e in source.Attributes()
                                                         where AttributeEquals(e, target.Attribute(e.Name))
                                                         select e;
            // Remove the attributes
            foreach (XAttribute a in attributesToRemove.ToList())
            {
                a.Remove();
            }

            foreach (XElement sourceChild in source.Elements().ToList())
            {
                XElement targetChild = FindElement(target, sourceChild);
                if (targetChild != null && !HasConflict(sourceChild, targetChild))
                {
                    Except(sourceChild, targetChild);
                    bool hasContent = sourceChild.HasAttributes || sourceChild.HasElements;
                    if (!hasContent)
                    {
                        // Remove the element if there is no content
                        sourceChild.Remove();
                        targetChild.Remove();
                    }
                }
            }
            return source;
        }
开发者ID:BreeeZe,项目名称:NuGetPackageExplorer,代码行数:34,代码来源:XElementExtensions.cs

示例12: ShouldEqual

		public static void ShouldEqual(this XElement actual, XElement expected)
		{
			if (actual == null)
			{
				if (expected == null)
				{
					return;
				}
				throw new EqualException(expected, null);
			}
			actual.Name.ShouldEqual(expected.Name);
			actual.Attributes().ShouldEqual(expected.Attributes());
			if (expected.HasElements != actual.HasElements)
			{
				throw new EqualException(expected, actual);
			}
			if (actual.HasElements)
			{
				actual.Elements().ShouldEqual(expected.Elements());
			}
			else
			{
				if (actual.Value != expected.Value)
				{
					throw new EqualException(expected, actual);
				}
			}
		}
开发者ID:muratbeyaztas,项目名称:Simple.Web,代码行数:28,代码来源:XElementExtensions.cs

示例13: RemoveAllNamespaces

 /// <summary>
 ///     An XElement extension method that removes all namespaces described by @this.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <returns>An XElement.</returns>
 public static XElement RemoveAllNamespaces(this XElement @this)
 {
     return new XElement(@this.Name.LocalName,
         (from n in @this.Nodes()
             select ((n is XElement) ? RemoveAllNamespaces(n as XElement) : n)),
         (@this.HasAttributes) ? (from a in @this.Attributes() select a) : null);
 }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:12,代码来源:XElement.RemoveAllNamespaces.cs

示例14: TryGetAttribute

 public static XAttribute TryGetAttribute(this XElement element, XName attributeName)
 {
     var attribute = element.Attribute(attributeName) ??
                     element.Attributes().SingleOrDefault(
                         a => a.Name.ToString().Homogenize() == attributeName.ToString().Homogenize());
     return attribute ?? new XAttribute(attributeName, string.Empty);
 }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:7,代码来源:XElementExtensions.cs

示例15: DescribeSelector

 public static string DescribeSelector(this XElement e)
 {
     var me = e.Name.ToString();
     if (e.HasAttributes)
         me += "[" + e.Attributes().Describe() + "]";
     return me;
 }
开发者ID:veracross,项目名称:ncontrib,代码行数:7,代码来源:XDocumentExtensions.cs


注:本文中的this.Attributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。