本文整理汇总了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];
}
示例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;
}