StyleSheetExtensions
Defines a set of extension methods for style sheets.
using AngleSharp.Dom;
using AngleSharp.Dom.Css;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AngleSharp.Extensions
{
public static class StyleSheetExtensions
{
public static IEnumerable<TRule> RulesOf<TRule>(this IEnumerable<IStyleSheet> sheets) where TRule : ICssRule
{
if (sheets == null)
throw new ArgumentNullException("sheets");
return (from m in sheets
where !m.IsDisabled
select m).OfType<ICssStyleSheet>().SelectMany((ICssStyleSheet m) => m.Rules).OfType<TRule>();
}
public static IEnumerable<ICssStyleRule> StylesWith(this IEnumerable<IStyleSheet> sheets, ISelector selector)
{
if (selector == null)
throw new ArgumentNullException("selector");
string selectorText = selector.Text;
return from m in sheets.RulesOf<ICssStyleRule>()
where m.SelectorText == selectorText
select m;
}
}
}