當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。