CssMarginProperty
sealed class CssMarginProperty : CssShorthandProperty, ICssMarginProperty, ICssProperty, ICssMarginBottomProperty, ICssMarginLeftProperty, ICssMarginRightProperty, ICssMarginTopProperty
Information can be found on MDN:
https://developer.mozilla.org/en-US/docs/Web/CSS/margin
using AngleSharp.Css;
using AngleSharp.Extensions;
using System;
using System.Collections.Generic;
namespace AngleSharp.Dom.Css
{
internal sealed class CssMarginProperty : CssShorthandProperty, ICssMarginProperty, ICssProperty, ICssMarginBottomProperty, ICssMarginLeftProperty, ICssMarginRightProperty, ICssMarginTopProperty
{
internal static readonly IValueConverter<Tuple<ICssValue, ICssValue, ICssValue, ICssValue>> Converter = CssMarginPartProperty.Converter.Val().Periodic();
private readonly CssMarginTopProperty _top;
private readonly CssMarginRightProperty _right;
private readonly CssMarginBottomProperty _bottom;
private readonly CssMarginLeftProperty _left;
public Length? Top => _top.Top;
public Length? Right => _right.Right;
public Length? Bottom => _bottom.Bottom;
public Length? Left => _left.Left;
internal CssMarginProperty(CssStyleDeclaration rule)
: base(PropertyNames.Margin, rule, PropertyFlags.None)
{
_top = Get<CssMarginTopProperty>();
_right = Get<CssMarginRightProperty>();
_bottom = Get<CssMarginBottomProperty>();
_left = Get<CssMarginLeftProperty>();
}
protected override bool IsValid(ICssValue value)
{
return Converter.TryConvert(value, delegate(Tuple<ICssValue, ICssValue, ICssValue, ICssValue> m) {
_top.TrySetValue(m.Item1);
_right.TrySetValue(m.Item2);
_bottom.TrySetValue(m.Item3);
_left.TrySetValue(m.Item4);
});
}
internal override string SerializeValue(IEnumerable<CssProperty> properties)
{
if (!IsComplete(properties))
return string.Empty;
return CssShorthandProperty.SerializePeriodic(_top, _right, _bottom, _left);
}
}
}