本文整理汇总了C#中IHtmlElement.Siblings方法的典型用法代码示例。如果您正苦于以下问题:C# IHtmlElement.Siblings方法的具体用法?C# IHtmlElement.Siblings怎么用?C# IHtmlElement.Siblings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHtmlElement
的用法示例。
在下文中一共展示了IHtmlElement.Siblings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArgumentNullException
bool ICssPseudoClassSelector.IsEligible( IHtmlElement element )
{
if ( element == null )
throw new ArgumentNullException( "element" );
switch ( _name )
{
case "only-child":
return element.Siblings().Count() == 1;
case "only-of-type":
return element.Siblings( element.Name ).Count() == 1;
case "empty":
return element.Nodes().Count( n => n is IHtmlElement || n is IHtmlTextNode ) == 0;//只有元素和文本节点视为有内容 http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#empty-pseudo
default:
throw new InvalidOperationException();
}
}
示例2: CreateIdentity
private static string CreateIdentity( IHtmlElement element, bool ancestorsCreate )
{
string parentId;
var parentElement = element.Parent();
if ( parentElement != null )
{
parentId = Identity( parentElement );
if ( parentId == null )
{
if ( ancestorsCreate )
parentId = Identity( parentElement, true, true );
else
parentId = CreateIdentity( parentElement, false );
}
}
else
{
if ( element.Container is IHtmlDocument )
parentId = null;
else
throw new InvalidOperationException();
}
var name = GetElementName( element );
var builder = new StringBuilder();
if ( !string.IsNullOrEmpty( parentId ) )
builder.AppendFormat( "{0}_", parentId );
builder.Append( name );
string identity;
if ( element.Siblings().Where( e => GetElementName( e ).EqualsIgnoreCase( GetElementName( element ) ) ).IsSingle() )
identity = builder.ToString();
var index = element.SiblingsBeforeSelf().Count( e => GetElementName( e ).EqualsIgnoreCase( GetElementName( element ) ) );
builder.Append( index + 1 );
identity = builder.ToString();
return EnsureUniqueness( identity, element.Document );
}