AngleSharp by Florian Rappl

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

 Converters

static class Converters
A set of already constructed CSS value converters.
using AngleSharp.Css.ValueConverters; using AngleSharp.Css.Values; using AngleSharp.Dom; using AngleSharp.Dom.Css; using AngleSharp.Extensions; using System; namespace AngleSharp.Css { internal static class Converters { private class ImageSource { public static IImageSource From(string url) { return null; } } public static readonly IValueConverter<Length> LineWidthConverter = new StructValueConverter<Length>(ValueExtensions.ToBorderWidth); public static readonly IValueConverter<Length> LineHeightConverter = new StructValueConverter<Length>(ValueExtensions.ToLineHeight); public static readonly IValueConverter<Length> BorderSliceConverter = new StructValueConverter<Length>(ValueExtensions.ToBorderSlice); public static readonly IValueConverter<Length> ImageBorderWidthConverter = new StructValueConverter<Length>(ValueExtensions.ToImageBorderWidth); public static readonly IValueConverter<Length> LengthConverter = new StructValueConverter<Length>(ValueExtensions.ToLength); public static readonly IValueConverter<Resolution> ResolutionConverter = new StructValueConverter<Resolution>(ValueExtensions.ToResolution); public static readonly IValueConverter<Frequency> FrequencyConverter = new StructValueConverter<Frequency>(ValueExtensions.ToFrequency); public static readonly IValueConverter<Time> TimeConverter = new StructValueConverter<Time>(ValueExtensions.ToTime); public static readonly IValueConverter<string> UrlConverter = new ClassValueConverter<string>(ValueExtensions.ToUri); public static readonly IValueConverter<string> StringConverter = new ClassValueConverter<string>(ValueExtensions.ToCssString); public static readonly IValueConverter<string> IdentifierConverter = new ClassValueConverter<string>(ValueExtensions.ToIdentifier); public static readonly IValueConverter<string> AnimatableConverter = new ClassValueConverter<string>(ValueExtensions.ToAnimatableIdentifier); public static readonly IValueConverter<int> IntegerConverter = new StructValueConverter<int>(ValueExtensions.ToInteger); public static readonly IValueConverter<Angle> AngleConverter = new StructValueConverter<Angle>(ValueExtensions.ToAngle); public static readonly IValueConverter<float> NumberConverter = new StructValueConverter<float>(ValueExtensions.ToSingle); public static readonly IValueConverter<Percent> PercentConverter = new StructValueConverter<Percent>(ValueExtensions.ToPercent); public static readonly IValueConverter<byte> ByteConverter = new StructValueConverter<byte>(ValueExtensions.ToByte); public static readonly IValueConverter<Color> PureColorConverter = new StructValueConverter<Color>(ValueExtensions.ToColor); public static readonly IValueConverter<Length> LengthOrPercentConverter = new StructValueConverter<Length>(ValueExtensions.ToDistance); public static readonly IValueConverter<Angle> SideOrCornerConverter = WithAny(Assign(Keywords.Left, -1).Or(Keywords.Right, 1).Option(0), Assign(Keywords.Top, 1).Or(Keywords.Bottom, -1).Option(0)).To((Tuple<double, double> m) => new Angle((float)(Math.Atan2(m.Item1, m.Item2) * 180 / 3.141592653589793), Angle.Unit.Deg)); public static readonly IValueConverter<Point> PointConverter = Construct(delegate { IValueConverter<Length> valueConverter13 = Assign(Keywords.Left, Length.Zero).Or(Keywords.Right, new Length(100, Length.Unit.Percent)).Or(Keywords.Center, new Length(50, Length.Unit.Percent)); IValueConverter<Length> valueConverter14 = Assign(Keywords.Top, Length.Zero).Or(Keywords.Bottom, new Length(100, Length.Unit.Percent)).Or(Keywords.Center, new Length(50, Length.Unit.Percent)); IValueConverter<Length> valueConverter15 = valueConverter13.Or(LengthOrPercentConverter).Required(); IValueConverter<Length> valueConverter16 = valueConverter14.Or(LengthOrPercentConverter).Required(); return LengthOrPercentConverter.To((Length m) => new Point(m, Length.Half)).Or(Toggle(Keywords.Left, Keywords.Right).To((bool m) => new Point(m ? Length.Zero : Length.Full, Length.Half))).Or(Toggle(Keywords.Top, Keywords.Bottom).To((bool m) => new Point(Length.Half, m ? Length.Zero : Length.Full))) .Or(Keywords.Center, Point.Center) .Or(WithOrder(valueConverter15, valueConverter16).To((Tuple<Length, Length> m) => new Point(m.Item1, m.Item2))) .Or(WithOrder(valueConverter16, valueConverter15).To((Tuple<Length, Length> m) => new Point(m.Item2, m.Item1))) .Or(WithOrder(valueConverter13, valueConverter14, LengthOrPercentConverter).To((Tuple<Length, Length, Length> m) => new Point(m.Item1, m.Item2.Add(m.Item3)))) .Or(WithOrder(valueConverter13, LengthOrPercentConverter, valueConverter14).To((Tuple<Length, Length, Length> m) => new Point(m.Item1.Add(m.Item2), m.Item3))) .Or(WithOrder(valueConverter13, LengthOrPercentConverter, valueConverter14, LengthOrPercentConverter).To((Tuple<Length, Length, Length, Length> m) => new Point(m.Item1.Add(m.Item2), m.Item3.Add(m.Item4)))); }); public static readonly IValueConverter<string> AttrConverter = new FunctionValueConverter<string>(FunctionNames.Attr, WithArg(StringConverter.Or(IdentifierConverter))); public static readonly IValueConverter<StepsTimingFunction> StepsConverter = new FunctionValueConverter<StepsTimingFunction>(FunctionNames.Steps, WithArgs(IntegerConverter.Required(), Assign(Keywords.Start, true).Or(Keywords.End, false).Option(false), (Tuple<int, bool> m) => new StepsTimingFunction(m.Item1, m.Item2))); public static readonly IValueConverter<CubicBezierTimingFunction> CubicBezierConverter = Construct(delegate { IValueConverter<float> valueConverter12 = NumberConverter.Required(); return new FunctionValueConverter<CubicBezierTimingFunction>(FunctionNames.CubicBezier, WithArgs(valueConverter12, valueConverter12, valueConverter12, valueConverter12, (Tuple<float, float, float, float> m) => new CubicBezierTimingFunction(m.Item1, m.Item2, m.Item3, m.Item4))); }); public static readonly IValueConverter<Counter> CounterConverter = Construct(delegate { IValueConverter<string> first4 = IdentifierConverter.Required(); IValueConverter<string> valueConverter11 = IdentifierConverter.Option(Keywords.Decimal); IValueConverter<string> second2 = StringConverter.Required(); return new FunctionValueConverter<Counter>(FunctionNames.Counter, WithArgs(first4, valueConverter11, (Tuple<string, string> m) => new Counter(m.Item1, m.Item2, null))).Or(new FunctionValueConverter<Counter>(FunctionNames.Counters, WithArgs(first4, second2, valueConverter11, (Tuple<string, string, string> m) => new Counter(m.Item1, m.Item3, m.Item2)))); }); public static readonly IValueConverter<Shape> ShapeConverter = Construct(delegate { IValueConverter<Length> valueConverter10 = LengthConverter.Required(); return new FunctionValueConverter<Shape>(FunctionNames.Rect, WithArgs(valueConverter10, valueConverter10, valueConverter10, valueConverter10, (Tuple<Length, Length, Length, Length> m) => new Shape(m.Item1, m.Item2, m.Item3, m.Item4)).Or(WithArg(LengthConverter.Many(4, 4).To((Length[] m) => new Shape(m[0], m[1], m[2], m[3]))))); }).OrDefault(); public static readonly IValueConverter<LinearGradient> LinearGradientConverter = Construct(delegate { IValueConverter<Angle> secondary2 = SideOrCornerConverter.StartsWithKeyword(Keywords.To); IValueConverter<Angle> arguments = AngleConverter.Or(secondary2); GradientConverter<Angle> converter2 = new GradientConverter<Angle>(arguments, Angle.Half); return new FunctionValueConverter<LinearGradient>(FunctionNames.LinearGradient, converter2.To((Tuple<Angle, GradientStop[]> m) => new LinearGradient(m.Item1.Value, m.Item2, false))).Or(new FunctionValueConverter<LinearGradient>(FunctionNames.RepeatingLinearGradient, converter2.To((Tuple<Angle, GradientStop[]> m) => new LinearGradient(m.Item1.Value, m.Item2, true)))); }); public static readonly IValueConverter<RadialGradient> RadialGradientConverter = Construct(delegate { IValueConverter<Point> second = PointConverter.StartsWithKeyword(Keywords.At).Option(Point.Center); var anon = new { Width = Length.Zero, Height = Length.Zero, SizeMode = RadialGradient.SizeMode.FarthestCorner }; var primary = WithOrder(WithAny(Assign(Keywords.Circle, true).Option(true), LengthConverter.To((Length m) => new { Width = m, Height = m, SizeMode = RadialGradient.SizeMode.None }).Option(anon)), second); var primary2 = WithOrder(WithAny(Assign(Keywords.Ellipse, false).Option(false), LengthOrPercentConverter.Many(2, 2).To((Length[] m) => new { Width = m[0], Height = m[1], SizeMode = RadialGradient.SizeMode.None }).Option(anon)), second); var secondary = WithOrder(WithAny(Toggle(Keywords.Circle, Keywords.Ellipse).Option(false), Map.RadialGradientSizeModes.ToConverter().To((RadialGradient.SizeMode m) => new { Width = Length.Zero, Height = Length.Zero, SizeMode = m })), second); GradientConverter<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>> converter = new GradientConverter<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>>(primary.Or(primary2.Or(secondary)).To(m => Tuple.Create(m.Item1.Item1, m.Item1.Item2.Width, m.Item1.Item2.Height, m.Item1.Item2.SizeMode, m.Item2)), Tuple.Create(false, anon.Width, anon.Height, anon.SizeMode, Point.Center)); return new FunctionValueConverter<RadialGradient>(FunctionNames.RadialGradient, converter.To((Tuple<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>, GradientStop[]> m) => new RadialGradient(m.Item1.Item1, m.Item1.Item5, m.Item1.Item2, m.Item1.Item3, m.Item1.Item4, m.Item2, false))).Or(new FunctionValueConverter<RadialGradient>(FunctionNames.RepeatingRadialGradient, converter.To((Tuple<Tuple<bool, Length, Length, RadialGradient.SizeMode, Point>, GradientStop[]> m) => new RadialGradient(m.Item1.Item1, m.Item1.Item5, m.Item1.Item2, m.Item1.Item3, m.Item1.Item4, m.Item2, true)))); }); public static readonly IValueConverter<Color> RgbColorConverter = Construct(delegate { IValueConverter<byte> valueConverter9 = ByteConverter.Required(); return new FunctionValueConverter<Color>(FunctionNames.Rgb, WithArgs(valueConverter9, valueConverter9, valueConverter9, (Tuple<byte, byte, byte> m) => new Color(m.Item1, m.Item2, m.Item3))); }); public static readonly IValueConverter<Color> RgbaColorConverter = Construct(delegate { IValueConverter<byte> valueConverter8 = ByteConverter.Required(); IValueConverter<float> fourth = NumberConverter.Required(); return new FunctionValueConverter<Color>(FunctionNames.Rgba, WithArgs(valueConverter8, valueConverter8, valueConverter8, fourth, (Tuple<byte, byte, byte, float> m) => new Color(m.Item1, m.Item2, m.Item3, (double)m.Item4))); }); public static readonly IValueConverter<Color> HslColorConverter = Construct(delegate { IValueConverter<Percent> valueConverter7 = PercentConverter.Required(); IValueConverter<float> first3 = NumberConverter.Required(); return new FunctionValueConverter<Color>(FunctionNames.Hsl, WithArgs(first3, valueConverter7, valueConverter7, (Tuple<float, Percent, Percent> m) => Color.FromHsl(m.Item1 / 360, m.Item2.NormalizedValue, m.Item3.NormalizedValue))); }); public static readonly IValueConverter<Color> HslaColorConverter = Construct(delegate { IValueConverter<Percent> valueConverter5 = PercentConverter.Required(); IValueConverter<float> valueConverter6 = NumberConverter.Required(); return new FunctionValueConverter<Color>(FunctionNames.Hsla, WithArgs(valueConverter6, valueConverter5, valueConverter5, valueConverter6, (Tuple<float, Percent, Percent, float> m) => Color.FromHsla(m.Item1 / 360, m.Item2.NormalizedValue, m.Item3.NormalizedValue, m.Item4))); }); public static readonly IValueConverter<PerspectiveTransform> PerspectiveConverter = Construct(() => new FunctionValueConverter<PerspectiveTransform>(FunctionNames.Perspective, WithArg(LengthConverter.To((Length m) => new PerspectiveTransform(m))))); public static readonly IValueConverter<MatrixTransform> MatrixTransformConverter = Construct(() => new FunctionValueConverter<MatrixTransform>(FunctionNames.Matrix, WithArgs(NumberConverter, 6, (float[] m) => new MatrixTransform(new float[15] { m[0], m[1], 0, 0, m[2], m[3], 0, 0, 0, 1, 0, m[4], m[5], 0, 1 }))).Or(new FunctionValueConverter<MatrixTransform>(FunctionNames.Matrix3d, WithArgs(NumberConverter, 16, (float[] m) => new MatrixTransform(m))))); public static readonly IValueConverter<TranslateTransform> TranslateTransformConverter = Construct(delegate { IValueConverter<Length> first2 = LengthOrPercentConverter.Required(); IValueConverter<Length> valueConverter4 = LengthOrPercentConverter.Option(Length.Zero); return new FunctionValueConverter<TranslateTransform>(FunctionNames.Translate, WithArgs(first2, valueConverter4, (Tuple<Length, Length> m) => new TranslateTransform(m.Item1, m.Item2, Length.Zero))).Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.Translate3d, WithArgs(first2, valueConverter4, valueConverter4, (Tuple<Length, Length, Length> m) => new TranslateTransform(m.Item1, m.Item2, m.Item3)))).Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.TranslateX, WithArg(LengthOrPercentConverter.To((Length m) => new TranslateTransform(m, Length.Zero, Length.Zero))))).Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.TranslateY, WithArg(LengthOrPercentConverter.To((Length m) => new TranslateTransform(Length.Zero, m, Length.Zero))))) .Or(new FunctionValueConverter<TranslateTransform>(FunctionNames.TranslateZ, WithArg(LengthOrPercentConverter.To((Length m) => new TranslateTransform(Length.Zero, Length.Zero, m))))); }); public static readonly IValueConverter<ScaleTransform> ScaleTransformConverter = Construct(delegate { IValueConverter<float> first = NumberConverter.Required(); IValueConverter<float> valueConverter3 = NumberConverter.Option(NaN); return new FunctionValueConverter<ScaleTransform>(FunctionNames.Scale, WithArgs(first, valueConverter3, (Tuple<float, float> m) => new ScaleTransform(m.Item1, float.IsNaN(m.Item2) ? m.Item1 : m.Item2, 1))).Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.Scale3d, WithArgs(first, valueConverter3, valueConverter3, (Tuple<float, float, float> m) => new ScaleTransform(m.Item1, float.IsNaN(m.Item2) ? m.Item1 : m.Item2, float.IsNaN(m.Item3) ? m.Item1 : m.Item3)))).Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.ScaleX, WithArg(NumberConverter.To((float m) => new ScaleTransform(m, 1, 1))))).Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.ScaleY, WithArg(NumberConverter.To((float m) => new ScaleTransform(1, m, 1))))) .Or(new FunctionValueConverter<ScaleTransform>(FunctionNames.ScaleZ, WithArg(NumberConverter.To((float m) => new ScaleTransform(1, 1, m))))); }); public static readonly IValueConverter<RotateTransform> RotateTransformConverter = Construct(delegate { IValueConverter<float> valueConverter2 = NumberConverter.Required(); return new FunctionValueConverter<RotateTransform>(FunctionNames.Rotate, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateZ(m.Value)))).Or(new FunctionValueConverter<RotateTransform>(FunctionNames.Rotate3d, WithArgs(valueConverter2, valueConverter2, valueConverter2, AngleConverter.Required(), (Tuple<float, float, float, Angle> m) => new RotateTransform(m.Item1, m.Item2, m.Item3, m.Item4.Value)))).Or(new FunctionValueConverter<RotateTransform>(FunctionNames.RotateX, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateX(m.Value))))).Or(new FunctionValueConverter<RotateTransform>(FunctionNames.RotateY, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateY(m.Value))))) .Or(new FunctionValueConverter<RotateTransform>(FunctionNames.RotateZ, WithArg(AngleConverter.To((Angle m) => RotateTransform.RotateZ(m.Value))))); }); public static readonly IValueConverter<SkewTransform> SkewTransformConverter = Construct(delegate { IValueConverter<Angle> valueConverter = AngleConverter.Required(); return new FunctionValueConverter<SkewTransform>(FunctionNames.Skew, WithArgs(valueConverter, valueConverter, (Tuple<Angle, Angle> m) => new SkewTransform(m.Item1.Value, m.Item2.Value))).Or(new FunctionValueConverter<SkewTransform>(FunctionNames.SkewX, WithArg(AngleConverter.To((Angle m) => new SkewTransform(m.Value, 0))))).Or(new FunctionValueConverter<SkewTransform>(FunctionNames.SkewY, WithArg(AngleConverter.To((Angle m) => new SkewTransform(0, m.Value))))); }); public static readonly IValueConverter<ITimingFunction> TransitionConverter = new DictionaryValueConverter<ITimingFunction>(Map.TimingFunctions).Or(StepsConverter.To((Func<StepsTimingFunction, ITimingFunction>)((StepsTimingFunction m) => m))).Or(CubicBezierConverter.To((Func<CubicBezierTimingFunction, ITimingFunction>)((CubicBezierTimingFunction m) => m))); public static readonly IValueConverter<IImageSource> GradientConverter = LinearGradientConverter.To((Func<LinearGradient, IImageSource>)((LinearGradient m) => m)).Or(RadialGradientConverter.To((Func<RadialGradient, IImageSource>)((RadialGradient m) => m))); public static readonly IValueConverter<ITransform> TransformConverter = MatrixTransformConverter.To((Func<MatrixTransform, ITransform>)((MatrixTransform m) => m)).Or(ScaleTransformConverter.To((Func<ScaleTransform, ITransform>)((ScaleTransform m) => m))).Or(RotateTransformConverter.To((Func<RotateTransform, ITransform>)((RotateTransform m) => m))) .Or(TranslateTransformConverter.To((Func<TranslateTransform, ITransform>)((TranslateTransform m) => m))) .Or(SkewTransformConverter.To((Func<SkewTransform, ITransform>)((SkewTransform m) => m))) .Or(PerspectiveConverter.To((Func<PerspectiveTransform, ITransform>)((PerspectiveTransform m) => m))); public static readonly IValueConverter<Color> ColorConverter = PureColorConverter.Or(RgbColorConverter.Or(RgbaColorConverter)).Or(HslColorConverter.Or(HslaColorConverter)); public static readonly IValueConverter<Color> CurrentColorConverter = ColorConverter.WithCurrentColor(); public static readonly IValueConverter<Color?> InvertedColorConverter = CurrentColorConverter.ToNullable().Or(Keywords.Invert, null); public static readonly IValueConverter<Tuple<int, int>> RatioConverter = WithOrder(IntegerConverter.Required(), IntegerConverter.StartsWithDelimiter().Required()); public static readonly IValueConverter<Shadow> ShadowConverter = WithAny(Assign(Keywords.Inset, true).Option(false), LengthConverter.Many(2, 4).Required(), ColorConverter.WithCurrentColor().Option(Color.Black)).To((Tuple<bool, Length[], Color> m) => new Shadow(m.Item1, m.Item2[0], m.Item2[1], Get(m.Item2, 2, Length.Zero), Get(m.Item2, 3, Length.Zero), m.Item3)); public static readonly IValueConverter<Shadow[]> MultipleShadowConverter = ShadowConverter.FromList().Or(Keywords.None, new Shadow[0]); public static readonly IValueConverter<IImageSource> ImageSourceConverter = UrlConverter.To((string m) => ImageSource.From(m)).Or(GradientConverter); public static readonly IValueConverter<IImageSource> OptionalImageSourceConverter = ImageSourceConverter.Or(Keywords.None, null); public static readonly IValueConverter<IImageSource[]> MultipleImageSourceConverter = ImageSourceConverter.FromList().Or(Keywords.None, new IImageSource[0]); public static readonly IValueConverter<Tuple<Length, Length?>> BorderRadiusConverter = WithOrder(LengthOrPercentConverter.Required(), LengthOrPercentConverter.ToNullable().Option(null)); public static readonly IValueConverter<int?> OptionalIntegerConverter = IntegerConverter.OrNullDefault(); public static readonly IValueConverter<int> PositiveIntegerConverter = IntegerConverter.Constraint((int m) => m >= 0); public static readonly IValueConverter<float> PositiveOrInfiniteNumberConverter = NumberConverter.Constraint((float m) => m >= 0).Or(Keywords.Infinite, Infinity); public static readonly IValueConverter<float?> OptionalNumberConverter = NumberConverter.ToNullable().Or(Keywords.None, null); public static readonly IValueConverter<Length> LengthOrNormalConverter = LengthConverter.Or(Keywords.Normal, new Length(1, Length.Unit.Em)); public static readonly IValueConverter<Length?> OptionalLengthConverter = LengthConverter.ToNullable().Or(Keywords.Normal, null); public static readonly IValueConverter<Length?> AutoLengthConverter = LengthConverter.OrNullDefault(); public static readonly IValueConverter<Length?> OptionalLengthOrPercentConverter = LengthOrPercentConverter.ToNullable().Or(Keywords.None, null); public static readonly IValueConverter<Length?> AutoLengthOrPercentConverter = LengthOrPercentConverter.OrNullDefault(); public static readonly IValueConverter<Length> FontSizeConverter = LengthOrPercentConverter.Or(Map.FontSizes.ToConverter().To((FontSize m) => m.ToLength())); public static readonly IValueConverter<LineStyle> LineStyleConverter = Map.LineStyles.ToConverter(); public static readonly IValueConverter<BackgroundAttachment> BackgroundAttachmentConverter = Map.BackgroundAttachments.ToConverter(); public static readonly IValueConverter<BoxModel> BoxModelConverter = Map.BoxModels.ToConverter(); public static readonly IValueConverter<AnimationDirection> AnimationDirectionConverter = Map.AnimationDirections.ToConverter(); public static readonly IValueConverter<AnimationFillStyle> AnimationFillStyleConverter = Map.AnimationFillStyles.ToConverter(); public static readonly IValueConverter<TextDecorationStyle> TextDecorationStyleConverter = Map.TextDecorationStyles.ToConverter(); public static readonly IValueConverter<ListPosition> ListPositionConverter = Map.ListPositions.ToConverter(); public static readonly IValueConverter<ListStyle> ListStyleConverter = Map.ListStyles.ToConverter(); public static readonly IValueConverter<BreakMode> BreakModeConverter = Map.BreakModes.ToConverter(); public static readonly IValueConverter<BreakMode> BreakInsideModeConverter = Map.BreakInsideModes.ToConverter(); public static readonly IValueConverter<BreakMode> PageBreakModeConverter = Map.PageBreakModes.ToConverter(); public static readonly IValueConverter<UnicodeMode> UnicodeModeConverter = Map.UnicodeModes.ToConverter(); public static readonly IValueConverter<Visibility> VisibilityConverter = Map.Visibilities.ToConverter(); public static readonly IValueConverter<PlayState> PlayStateConverter = Assign(Keywords.Running, PlayState.Running).Or(Keywords.Paused, PlayState.Paused); public static readonly IValueConverter<FontVariant> FontVariantConverter = Assign(Keywords.Normal, FontVariant.Normal).Or(Keywords.SmallCaps, FontVariant.SmallCaps); public static readonly IValueConverter<DirectionMode> DirectionModeConverter = Assign(Keywords.Ltr, DirectionMode.Ltr).Or(Keywords.Rtl, DirectionMode.Rtl); public static readonly IValueConverter<HorizontalAlignment> HorizontalAlignmentConverter = Map.HorizontalAlignments.ToConverter(); public static readonly IValueConverter<VerticalAlignment> VerticalAlignmentConverter = Map.VerticalAlignments.ToConverter(); public static readonly IValueConverter<Whitespace> WhitespaceConverter = Map.WhitespaceModes.ToConverter(); public static readonly IValueConverter<TextTransform> TextTransformConverter = Map.TextTransforms.ToConverter(); public static readonly IValueConverter<ObjectFitting> ObjectFittingConverter = Map.ObjectFittings.ToConverter(); public static readonly IValueConverter<PositionMode> PositionModeConverter = Map.PositionModes.ToConverter(); public static readonly IValueConverter<OverflowMode> OverflowModeConverter = Map.OverflowModes.ToConverter(); public static readonly IValueConverter<Floating> FloatingConverter = Map.FloatingModes.ToConverter(); public static readonly IValueConverter<DisplayMode> DisplayModeConverter = Map.DisplayModes.ToConverter(); public static readonly IValueConverter<ClearMode> ClearModeConverter = Map.ClearModes.ToConverter(); public static readonly IValueConverter<FontStretch> FontStretchConverter = Map.FontStretches.ToConverter(); public static readonly IValueConverter<FontStyle> FontStyleConverter = Map.FontStyles.ToConverter(); public static readonly IValueConverter<bool> TableLayoutConverter = Toggle(Keywords.Fixed, Keywords.Auto); public static readonly IValueConverter<bool> EmptyCellsConverter = Toggle(Keywords.Show, Keywords.Hide); public static readonly IValueConverter<bool> CaptionSideConverter = Toggle(Keywords.Top, Keywords.Bottom); public static readonly IValueConverter<bool> BackfaceVisibilityConverter = Toggle(Keywords.Visible, Keywords.Hidden); public static readonly IValueConverter<bool> BorderCollapseConverter = Toggle(Keywords.Separate, Keywords.Collapse); public static readonly IValueConverter<bool> BoxDecorationConverter = Toggle(Keywords.Clone, Keywords.Slice); public static readonly IValueConverter<bool> ColumnSpanConverter = Toggle(Keywords.All, Keywords.None); public static readonly IValueConverter<bool> ColumnFillConverter = Toggle(Keywords.Balance, Keywords.Auto); public static IValueConverter<T> Assign<T>(string identifier, T result) { return new IdentifierValueConverter<T>(identifier, result); } public static IValueConverter<bool> Toggle(string on, string off) { return Assign(on, true).Or(off, false); } public static IValueConverter<T[]> WithOrder<T>(IValueConverter<T> converter) { return new OrderedOptionsConverter<T>(converter); } public static IValueConverter<Tuple<T1, T2>> WithOrder<T1, T2>(IValueConverter<T1> first, IValueConverter<T2> second) { return new OrderedOptionsConverter<T1, T2>(first, second); } public static IValueConverter<Tuple<T1, T2, T3>> WithOrder<T1, T2, T3>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third) { return new OrderedOptionsConverter<T1, T2, T3>(first, second, third); } public static IValueConverter<Tuple<T1, T2, T3, T4>> WithOrder<T1, T2, T3, T4>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth) { return new OrderedOptionsConverter<T1, T2, T3, T4>(first, second, third, fourth); } public static IValueConverter<Tuple<T1, T2>> WithAny<T1, T2>(IValueConverter<T1> first, IValueConverter<T2> second) { return new UnorderedOptionsConverter<T1, T2>(first, second); } public static IValueConverter<Tuple<T1, T2, T3>> WithAny<T1, T2, T3>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third) { return new UnorderedOptionsConverter<T1, T2, T3>(first, second, third); } public static IValueConverter<Tuple<T1, T2, T3, T4>> WithAny<T1, T2, T3, T4>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth) { return new UnorderedOptionsConverter<T1, T2, T3, T4>(first, second, third, fourth); } public static IValueConverter<Tuple<T1, T2, T3, T4, T5>> WithAny<T1, T2, T3, T4, T5>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth) { return new UnorderedOptionsConverter<T1, T2, T3, T4, T5>(first, second, third, fourth, fifth); } public static IValueConverter<Tuple<T1, T2, T3, T4, T5, T6>> WithAny<T1, T2, T3, T4, T5, T6>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth, IValueConverter<T6> sixth) { return new UnorderedOptionsConverter<T1, T2, T3, T4, T5, T6>(first, second, third, fourth, fifth, sixth); } public static IValueConverter<Tuple<T1, T2, T3, T4, T5, T6, T7>> WithAny<T1, T2, T3, T4, T5, T6, T7>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth, IValueConverter<T6> sixth, IValueConverter<T7> seventh) { return new UnorderedOptionsConverter<T1, T2, T3, T4, T5, T6, T7>(first, second, third, fourth, fifth, sixth, seventh); } public static IValueConverter<Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>> WithAny<T1, T2, T3, T4, T5, T6, T7, T8>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, IValueConverter<T5> fifth, IValueConverter<T6> sixth, IValueConverter<T7> seventh, IValueConverter<T8> eighth) { return new UnorderedOptionsConverter<T1, T2, T3, T4, T5, T6, T7, T8>(first, second, third, fourth, fifth, sixth, seventh, eighth); } private static T Get<T>(T[] array, int index, T defaultValue) { if (array.Length <= index) return defaultValue; return array[index]; } private static IValueConverter<T> Construct<T>(Func<IValueConverter<T>> f) { return f(); } private static IValueConverter<T> WithArg<T>(IValueConverter<T> converter) { return converter; } private static IValueConverter<T> WithArgs<T1, T>(IValueConverter<T1> converter, int arguments, Func<T1[], T> transform) { return new ArgumentsValueConverter<T1>(converter, arguments).To(transform); } private static IValueConverter<T> WithArgs<T1, T2, T>(IValueConverter<T1> first, IValueConverter<T2> second, Func<Tuple<T1, T2>, T> converter) { return new ArgumentsValueConverter<T1, T2>(first, second).To(converter); } private static IValueConverter<T> WithArgs<T1, T2, T3, T>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, Func<Tuple<T1, T2, T3>, T> converter) { return new ArgumentsValueConverter<T1, T2, T3>(first, second, third).To(converter); } private static IValueConverter<T> WithArgs<T1, T2, T3, T4, T>(IValueConverter<T1> first, IValueConverter<T2> second, IValueConverter<T3> third, IValueConverter<T4> fourth, Func<Tuple<T1, T2, T3, T4>, T> converter) { return new ArgumentsValueConverter<T1, T2, T3, T4>(first, second, third, fourth).To(converter); } } }