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


C# XName.ToString方法代码示例

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


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

示例1: 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

示例2: TryGetAttributeValue

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

示例3: AddAttribute

        /// <summary>
        ///     Adds a new attribute to the element
        ///     Does not permit modification of an existing attribute.
        ///     Does not add empty or null attributes or values.
        /// </summary>
        /// <param name="element">The element to add the attribute to</param>
        /// <param name="attribute">The attribute to add</param>
        /// <param name="value">the value of the attribute to add</param>
        /// <returns>The element passed in. (Permits fluent usage)</returns>
        internal static XElement AddAttribute(this XElement element, XName attribute, string value) {
            if (element == null) {
                return null;
            }

            // we quietly ignore attempts to add empty data or attributes.
            if (string.IsNullOrWhiteSpace(value) || attribute == null || string.IsNullOrWhiteSpace(attribute.ToString())) {
                return element;
            }

            // Swidtag attributes can be added but not changed -- if it already exists, that's not permitted.
            var current = element.GetAttribute(attribute);
            if (!string.IsNullOrWhiteSpace(current)) {
                if (value != current) {
                    throw new Exception("Attempt to change Attribute '{0}' present in element '{1}'".format(attribute.LocalName, element.Name.LocalName));
                }

                // if the value was set to that already, don't worry about it.
                return element;
            }

            element.SetAttributeValue(attribute, value);

            return element;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:34,代码来源:Iso19770_2.cs

示例4: ShouldEqual

		public static void ShouldEqual(this XName actual, XName expected)
		{
			if (actual.ToString() != expected.ToString())
			{
				throw new EqualException(expected, actual);
			}
		}
开发者ID:muratbeyaztas,项目名称:Simple.Web,代码行数:7,代码来源:XNameExtensions.cs

示例5: GetAttribute

 /// <summary>
 ///     Gets the attribute value for a given element.
 /// </summary>
 /// <param name="element">the element that possesses the attribute</param>
 /// <param name="attribute">the attribute to find</param>
 /// <returns>the string value of the element. Returns null if the element or attribute does not exist.</returns>
 internal static string GetAttribute(this XElement element, XName attribute) {
     if (element == null || attribute == null || string.IsNullOrWhiteSpace(attribute.ToString())) {
         return null;
     }
     var a = element.Attribute(attribute);
     return a == null ? null : a.Value;
 }
开发者ID:vairam-svs,项目名称:oneget,代码行数:13,代码来源:Iso19770_2.cs

示例6: XsltContextFunctionAttribute

        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="name"></param>
        public XsltContextFunctionAttribute(XName name)
            : base(typeof(IXsltContextFunction))
        {
            Contract.Requires<ArgumentNullException>(name != null);

            this.expandedName = name.ToString();
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:11,代码来源:XsltContextFunctionAttribute.cs

示例7: FormatName

 public static string FormatName(this XElement element, XName name)
 {
     if (name.Namespace == null) return name.LocalName;
     if (name.Namespace == element.GetDefaultNamespace()) return name.LocalName;
     string prefix = element.GetPrefixOfNamespace(name.Namespace);
     if (!string.IsNullOrEmpty(prefix)) return prefix + ":" + name.LocalName;
     return name.ToString();
 }
开发者ID:JamesTryand,项目名称:Simple.OData.Client,代码行数:8,代码来源:XElementAsDictionaryExtension.cs

示例8: AreEqual

 private static bool AreEqual(XName left, XName right)
 {
     if (left == null && right == null) {
         return true;
     }
     if (left == null || right == null) {
         return false;
     }
     return left.ToString() == right.ToString();
 }
开发者ID:EddieGarmon,项目名称:XunitShould,代码行数:10,代码来源:AssertNames.cs

示例9: Descendants

        /// <summary>
        /// Returns a collection of the descendant elements for this document or element, in document order. Optionally ignores case.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="name"></param>
        /// <param name="ignoreCase"></param>
        /// <returns></returns>
        public static IEnumerable<XElement> Descendants( this XElement element, XName name, bool ignoreCase )
        {
            var collection = element.Descendants();

            if ( ignoreCase )
            {
                collection = collection.Where( p => p.Name.ToString().ToLower() == name.ToString().ToLower() );
            }

            return collection;
        }
开发者ID:Glazed,项目名称:Dredmor-XML-Validator,代码行数:18,代码来源:XmlExtensions.cs

示例10: 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

示例11: Attribute

 /// <summary>
 /// Returns the <see cref="System.Xml.Linq.XAttribute"/> of this <see cref="System.Xml.Linq.XElement"/> that
 /// has the specified <see cref="System.Xml.Linq.XName"/>, optionally ignoring case.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="name"></param>
 /// <param name="ignoreCase"></param>
 /// <returns></returns>
 public static XAttribute Attribute( this XElement element, XName name, bool ignoreCase )
 {
     if ( ignoreCase )
     {
         return element.Attributes().Where( p => p.Name.ToString().ToLower() == name.ToString().ToLower() ).FirstOrDefault();
     }
     else
     {
         return element.Attribute( name );
     }
 }
开发者ID:Glazed,项目名称:Dredmor-XML-Validator,代码行数:19,代码来源:XmlExtensions.cs

示例12: Element

    public static XElement Element(this XElement element, XName name, bool ignoreCase)
    {
        var el = element.Element(name);
        if (el != null)
            return el;

        if (!ignoreCase)
            return null;

        var elements = element.Elements().Where(e => e.Name.LocalName.ToString().ToLowerInvariant() == name.ToString().ToLowerInvariant());
        return elements.Count() == 0 ? null : elements.First();
    }
开发者ID:CedricDumont,项目名称:CExtensions-Net,代码行数:12,代码来源:Extensions.cs

示例13: Attribute

        // ignore case if set
        public static XAttribute Attribute( this XElement element, XName name, bool ignoreCase )
        {
            var at = element.Attribute( name );
            if (at != null)
                return at;

            if (!ignoreCase)
                return null;

            var ats = element.Attributes().Where( e => e.Name.LocalName.ToString().ToLowerInvariant() == name.ToString().ToLowerInvariant() );
            return ats.Count() == 0 ? null : ats.First();
        }
开发者ID:pjanec,项目名称:dirigent,代码行数:13,代码来源:XmlConfigReaderUtils.cs

示例14: GetAttribute

        /// <summary>
        ///     Gets the attribute value for a given element.
        /// </summary>
        /// <param name="element">the element that possesses the attribute</param>
        /// <param name="attribute">the attribute to find</param>
        /// <returns>the string value of the element. Returns null if the element or attribute does not exist.</returns>
        internal static string GetAttribute(this XElement element, XName attribute) {
            if (element == null || attribute == null || string.IsNullOrWhiteSpace(attribute.ToString())) {
                return null;
            }

            XAttribute result;

            // no name space, just check local name
            if (string.IsNullOrWhiteSpace(attribute.Namespace.NamespaceName))
            {
                result = element.Attributes().Where(attr => attr != null && string.Equals(attr.Name.LocalName, attribute.LocalName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            }
            else
            {
                result = element.Attribute(attribute);
            }

            return result == null ? null : result.Value;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:25,代码来源:Iso19770_2.cs

示例15: SetAttribute

        /// <summary>
        ///     Adds a new attribute to the element
        ///     Does not permit modification of an existing attribute.
        ///     Does not add empty or null attributes or values.
        /// </summary>
        /// <param name="element">The element to add the attribute to</param>
        /// <param name="attribute">The attribute to add</param>
        /// <param name="value">the value of the attribute to add</param>
        /// <returns>The element passed in. (Permits fluent usage)</returns>
        internal static XElement SetAttribute(this XElement element, XName attribute, string value) {
            if (element == null) {
                return null;
            }

            // we quietly ignore attempts to add empty data or attributes.
            if (attribute == null || string.IsNullOrWhiteSpace(attribute.ToString())) {
                return element;
            }

            if (element.Name.Namespace == attribute.Namespace || string.IsNullOrWhiteSpace(attribute.NamespaceName) || attribute.Namespace == Namespace.XmlNs || attribute.Namespace == Namespace.Xml) {
                element.SetAttributeValue(attribute.LocalName, value);
            } else {
                element.EnsureNamespaceAtTop(attribute.Namespace);
                element.SetAttributeValue(attribute, value);
            }

            return element;
        }
开发者ID:enavro,项目名称:SwidTag,代码行数:28,代码来源:XmlExtensions.cs


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