AngleSharp by Florian Rappl

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

.NET API 1,229,312 bytes

 CssMarginProperty

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; using System.Linq; namespace AngleSharp.Dom.Css { internal sealed class CssMarginProperty : CssShorthandProperty { private static readonly IValueConverter<Tuple<CssValue, CssValue, CssValue, CssValue>> Converter = Converters.AutoLengthOrPercentConverter.Val().Periodic(); internal CssMarginProperty(CssStyleDeclaration rule) : base(PropertyNames.Margin, rule, PropertyFlags.None) { } protected override bool IsValid(CssValue value) { return Converter.TryConvert(value, delegate(Tuple<CssValue, CssValue, CssValue, CssValue> m) { Get<CssMarginTopProperty>().TrySetValue(m.Item1); Get<CssMarginRightProperty>().TrySetValue(m.Item2); Get<CssMarginBottomProperty>().TrySetValue(m.Item3); Get<CssMarginLeftProperty>().TrySetValue(m.Item4); }); } internal override string SerializeValue(IEnumerable<CssProperty> properties) { CssMarginTopProperty cssMarginTopProperty = properties.OfType<CssMarginTopProperty>().FirstOrDefault(); CssMarginRightProperty cssMarginRightProperty = properties.OfType<CssMarginRightProperty>().FirstOrDefault(); CssMarginBottomProperty cssMarginBottomProperty = properties.OfType<CssMarginBottomProperty>().FirstOrDefault(); CssMarginLeftProperty cssMarginLeftProperty = properties.OfType<CssMarginLeftProperty>().FirstOrDefault(); if (cssMarginTopProperty == null || cssMarginRightProperty == null || cssMarginBottomProperty == null || cssMarginLeftProperty == null) return string.Empty; if (!cssMarginTopProperty.HasValue || !cssMarginRightProperty.HasValue || !cssMarginBottomProperty.HasValue || !cssMarginLeftProperty.HasValue) return string.Empty; return CssShorthandProperty.SerializePeriodic(cssMarginTopProperty, cssMarginRightProperty, cssMarginBottomProperty, cssMarginLeftProperty); } } }