當前位置: 首頁>>代碼示例>>C#>>正文


C# XPathNavigator.HasAttribute方法代碼示例

本文整理匯總了C#中System.Xml.XPath.XPathNavigator.HasAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XPathNavigator.HasAttribute方法的具體用法?C# XPathNavigator.HasAttribute怎麽用?C# XPathNavigator.HasAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XPath.XPathNavigator的用法示例。


在下文中一共展示了XPathNavigator.HasAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InferItemType

        internal static ItemType InferItemType(XPathNavigator item)
        {
            string value;

            if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out value) && XmlConvert.ToBoolean(value))
            {
                return ItemType.Property;
            }

            if (item.HasAttribute("key", Framework.Common.SData.Namespace) ||
                item.HasAttribute("uuid", Framework.Common.SData.Namespace) ||
                item.HasAttribute("lookup", Framework.Common.SData.Namespace) ||
                item.HasAttribute("descriptor", Framework.Common.SData.Namespace))
            {
                return ItemType.Object;
            }

            if (item.HasAttribute("url", Framework.Common.SData.Namespace) ||
                item.HasAttribute("uri", Framework.Common.SData.Namespace) ||
                item.HasAttribute("deleteMissing", Framework.Common.SData.Namespace))
            {
                return ItemType.PayloadCollection;
            }

            if (item.IsEmptyElement)
            {
                // workaround: Older versions of the SIF generate payload collections as empty namespace-less elements
                return string.IsNullOrEmpty(item.NamespaceURI) ? ItemType.PayloadCollection : ItemType.Property;
            }

            var children = item.SelectChildren(XPathNodeType.Element).Cast<XPathNavigator>();
            var childCount = children.Count();

            if (childCount == 0)
            {
                return ItemType.Property;
            }

            if (childCount > 1 && children.Select(child => child.LocalName).Distinct().Count() == 1)
            {
                if (children.All(child => InferItemType(child) == ItemType.Object))
                {
                    return ItemType.PayloadCollection;
                }
                if (children.All(child => InferItemType(child) == ItemType.Property))
                {
                    return ItemType.SimpleCollection;
                }
            }

            return ItemType.Object;
        }
開發者ID:jasonhuber,項目名稱:SDataUpdateNestedEntities,代碼行數:52,代碼來源:SDataPayload.cs

示例2: InferItemType

        internal static ItemType InferItemType(XPathNavigator item)
        {
            string value;

            if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out value) && XmlConvert.ToBoolean(value))
            {
                return ItemType.Property;
            }

            if (item.HasAttribute("key", Framework.Common.SData.Namespace) ||
                item.HasAttribute("uuid", Framework.Common.SData.Namespace) ||
                item.HasAttribute("lookup", Framework.Common.SData.Namespace) ||
                item.HasAttribute("descriptor", Framework.Common.SData.Namespace))
            {
                return ItemType.Object;
            }

            if (item.HasAttribute("url", Framework.Common.SData.Namespace) ||
                item.HasAttribute("deleteMissing", Framework.Common.SData.Namespace) ||
                item.IsEmptyElement)
            {
                return ItemType.PayloadCollection;
            }

            var children = item.SelectChildren(XPathNodeType.Element).Cast<XPathNavigator>();
            var childCount = children.Count();

            if (childCount == 0)
            {
                return ItemType.Property;
            }

            if (children.Select(child => child.LocalName).Distinct().Count() == 1 &&
                children.All(child => InferItemType(child) == ItemType.Object))
            {
                return ItemType.PayloadCollection;
            }

            if (children.Select(child => child.LocalName).Distinct().Count() == 1 &&
                children.All(child => InferItemType(child) == ItemType.Property))
            {
                return ItemType.SimpleCollection;
            }

            return ItemType.Object;
        }
開發者ID:RyanFarley,項目名稱:SDataCSharpClientLib,代碼行數:46,代碼來源:SDataPayload.cs


注:本文中的System.Xml.XPath.XPathNavigator.HasAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。