ChildSelector
Base class for all nth-child (or related) selectors.
using AngleSharp.Css;
using AngleSharp.Extensions;
using System.IO;
namespace AngleSharp.Dom.Css
{
internal abstract class ChildSelector : CssNode, ISelector, ICssNode, IStyleFormattable
{
private readonly string _name;
protected int _step;
protected int _offset;
protected ISelector _kind;
public Priority Specifity => Priority.OneClass;
public string Text => this.ToCss();
public ChildSelector(string name)
{
_name = name;
}
internal ChildSelector With(int step, int offset, ISelector kind)
{
_step = step;
_offset = offset;
_kind = kind;
return this;
}
public abstract bool Match(IElement element);
public override void ToCss(TextWriter writer, IStyleFormatter formatter)
{
string text = _step.ToString();
string text2 = string.Empty;
if (_offset > 0)
text2 = "+" + _offset.ToString();
else if (_offset < 0) {
text2 = _offset.ToString();
}
writer.Write(":{0}({1}n{2})", new object[3] {
_name,
text,
text2
});
}
}
}