ContinuousValueConverter
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 ContinuousValueConverter : IValueConverter
{
private sealed class OptionsValue : IPropertyValue
{
private readonly IPropertyValue[] _options;
private readonly CssValue _value;
public string CssText => string.Join(" ", from m in _options
where !string.IsNullOrEmpty(m.CssText)
select m.CssText);
public CssValue Original => _value;
public OptionsValue(IPropertyValue[] options, IEnumerable<CssToken> tokens)
{
_options = options;
_value = 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) {
if (list.Count > 0)
list.Add(CssToken.Whitespace);
list.AddRange(cssValue);
}
}
return new CssValue(list);
}
}
private readonly IValueConverter _converter;
public ContinuousValueConverter(IValueConverter converter)
{
_converter = converter;
}
public IPropertyValue Convert(IEnumerable<CssToken> value)
{
List<CssToken> list = new List<CssToken>(value);
List<IPropertyValue> list2 = new List<IPropertyValue>();
if (list.Count == 0)
return null;
while (list.Count != 0) {
IPropertyValue propertyValue = _converter.VaryStart(list);
if (propertyValue == null)
return null;
list2.Add(propertyValue);
}
return new OptionsValue(list2.ToArray(), value);
}
public IPropertyValue Construct(CssProperty[] properties)
{
return properties.Guard<OptionsValue>();
}
}
}