AngleSharp by AngleSharp

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

.NET API 1,261,568 bytes

 ListValueConverter

using AngleSharp.Dom.Css; using AngleSharp.Extensions; using AngleSharp.Parser.Css; using System; using System.Collections.Generic; using System.Linq; namespace AngleSharp.Css.ValueConverters { internal sealed class ListValueConverter : IValueConverter { private sealed class ListValue : IPropertyValue { private readonly IPropertyValue[] _values; private readonly CssValue _value; public string CssText => string.Join(", ", from m in _values select m.CssText); public CssValue Original => _value; public ListValue(IPropertyValue[] values, IEnumerable<CssToken> tokens) { _values = values; _value = new CssValue(tokens); } public CssValue ExtractFor(string name) { List<CssToken> list = new List<CssToken>(); IPropertyValue[] values = _values; foreach (IPropertyValue propertyValue in values) { CssValue cssValue = propertyValue.ExtractFor(name); if (cssValue != null) { if (list.Count > 0) list.Add(CssToken.Comma); list.AddRange(cssValue); } } return new CssValue(list); } } private readonly IValueConverter _converter; public ListValueConverter(IValueConverter converter) { _converter = converter; } public IPropertyValue Convert(IEnumerable<CssToken> value) { List<List<CssToken>> list = value.ToList(); IPropertyValue[] array = new IPropertyValue[list.Count]; for (int i = 0; i < list.Count; i++) { array[i] = _converter.Convert(list[i]); if (array[i] == null) return null; } if (array.Length == 1) return array[0]; return new ListValue(array, value); } public IPropertyValue Construct(CssProperty[] properties) { IPropertyValue propertyValue = properties.Guard<ListValue>(); if (propertyValue == null) { List<List<CssToken>>[] array = new List<List<CssToken>>[properties.Length]; CssProperty[] array2 = new CssProperty[properties.Length]; int num = 0; for (int i = 0; i < properties.Length; i++) { IPropertyValue declaredValue = properties[i].DeclaredValue; array[i] = ((declaredValue != null) ? declaredValue.Original.ToList() : new List<List<CssToken>>()); array2[i] = Factory.Properties.CreateLonghand(properties[i].Name); num = Math.Max(num, array[i].Count); } IPropertyValue[] array3 = new IPropertyValue[num]; for (int j = 0; j < num; j++) { for (int k = 0; k < array2.Length; k++) { List<List<CssToken>> list = array[k]; IEnumerable<CssToken> tokens = (list.Count > j) ? list[j] : Enumerable.Empty<CssToken>(); array2[k].TrySetValue(new CssValue(tokens)); } array3[j] = _converter.Construct(array2); } propertyValue = new ListValue(array3, Enumerable.Empty<CssToken>()); } return propertyValue; } } }