AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.8.6" />

.NET API 1,174,016 bytes

 UnorderedOptionsConverter

using AngleSharp.Dom.Css; using AngleSharp.Extensions; using AngleSharp.Parser.Css; using System.Collections.Generic; using System.Linq; namespace AngleSharp.Css.ValueConverters { internal sealed class UnorderedOptionsConverter : IValueConverter { private sealed class OptionsValue : IPropertyValue { private readonly IPropertyValue[] _options; private readonly CssValue _original; public string CssText => string.Join(" ", from m in _options where !string.IsNullOrEmpty(m.CssText) select m.CssText); public CssValue Original => _original; public OptionsValue(IPropertyValue[] options, IEnumerable<CssToken> tokens) { _options = options; _original = new CssValue(tokens); } public CssValue ExtractFor(string name) { List<CssToken> list = new List<CssToken>(); IPropertyValue[] options = _options; foreach (IPropertyValue propertyValue in options) { CssValue cssValue = propertyValue.ExtractFor(name); if (cssValue != null && cssValue.Count > 0) { if (list.Count > 0) list.Add(CssToken.Whitespace); list.AddRange(cssValue); } } return new CssValue(list); } } private readonly IValueConverter[] _converters; public UnorderedOptionsConverter(params IValueConverter[] converters) { _converters = converters; } public IPropertyValue Convert(IEnumerable<CssToken> value) { List<CssToken> list = new List<CssToken>(value); IPropertyValue[] array = new IPropertyValue[_converters.Length]; for (int i = 0; i < _converters.Length; i++) { array[i] = _converters[i].VaryAll(list); if (array[i] == null) return null; } if (list.Count != 0) return null; return new OptionsValue(array, value); } public IPropertyValue Construct(CssProperty[] properties) { IPropertyValue propertyValue = properties.Guard<OptionsValue>(); if (propertyValue == null) { IPropertyValue[] array = new IPropertyValue[_converters.Length]; for (int i = 0; i < _converters.Length; i++) { IPropertyValue propertyValue2 = _converters[i].Construct(properties); if (propertyValue2 == null) return null; array[i] = propertyValue2; } propertyValue = new OptionsValue(array, Enumerable.Empty<CssToken>()); } return propertyValue; } } }