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


C# IXPathNavigable.GetNavigator方法代码示例

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


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

示例1: FindBestMatchingType

        public static Type FindBestMatchingType(this Type elementType, IXPathNavigable node)
        {
            if (elementType == null)
            {
                throw new ArgumentNullException("elementType");
            }

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var navigator = node.GetNavigator();
            var possibleTypes = GetMatchingTypes(elementType).ToList();
            var matchingTypes = new List<Type>();

            // The node name should already be folded to lower case when the HTML was read
            var nodeName = navigator.Name;

            foreach (var possibleType in possibleTypes)
            {
                var attributes =
                    possibleType.GetCustomAttributes(typeof(SupportedTagAttribute), true)
                        .OfType<SupportedTagAttribute>();

                foreach (var attribute in attributes)
                {
                    if (nodeName.Equals(attribute.TagName, StringComparison.OrdinalIgnoreCase) == false)
                    {
                        continue;
                    }

                    if (attribute.HasAttributeFilter)
                    {
                        // The attribute name should already be folded to lower case when the HTML was read
                        var queryAttributeName = attribute.AttributeName.ToLowerInvariant();

                        var matchingAttribute = navigator.GetAttribute(queryAttributeName, string.Empty);

                        if (matchingAttribute.Equals(attribute.AttributeValue, StringComparison.OrdinalIgnoreCase))
                        {
                            matchingTypes.Add(possibleType);
                        }
                    }
                    else
                    {
                        matchingTypes.Add(possibleType);
                    }
                }
            }

            if (matchingTypes.Count == 0)
            {
                return typeof(AnyHtmlElement);
            }

            if (matchingTypes.Count > 1)
            {
                var matchingTypeNames = matchingTypes.Aggregate(string.Empty, (x, y) => x + Environment.NewLine + y);
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Resources.TypeExtensions_MultipleTypeMatchesForNode,
                    elementType.FullName,
                    navigator.OuterXml,
                    matchingTypeNames);

                throw new InvalidHtmlElementMatchException(message);
            }

            return matchingTypes[0];
        }
开发者ID:roryprimrose,项目名称:Headless,代码行数:71,代码来源:TypeExtensions.cs

示例2: BuildSupportedTagsMessage

        /// <summary>
        /// Builds the supported tags message.
        /// </summary>
        /// <param name="node">
        /// The node.
        /// </param>
        /// <param name="tags">
        /// The tags.
        /// </param>
        /// <returns>
        /// A <see cref="string"/> value.
        /// </returns>
        private static string BuildSupportedTagsMessage(IXPathNavigable node, IEnumerable<SupportedTagAttribute> tags)
        {
            var supportedTags = tags.Select(x => x.ToString()).Aggregate((i, j) => i + Environment.NewLine + j);

            var navigator = node.GetNavigator();

            var message = string.Format(
                CultureInfo.CurrentCulture,
                "The specified '{0}' element is invalid. The supported tags for this node are: {1}",
                navigator.Name,
                supportedTags);

            return message;
        }
开发者ID:roryprimrose,项目名称:Headless,代码行数:26,代码来源:InvalidHtmlElementException.cs


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