From d10e8eb8f74b49355d5132ddcc530089f8224d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 20 Nov 2018 01:01:57 +0100 Subject: [PATCH] Use invariant strings --- src/ThemeEditor.ViewModels/Extensions.cs | 24 +++++++++++++------ .../Converters/ThicknessViewModelConverter.cs | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/ThemeEditor.ViewModels/Extensions.cs b/src/ThemeEditor.ViewModels/Extensions.cs index 6bb9ffb..7899356 100644 --- a/src/ThemeEditor.ViewModels/Extensions.cs +++ b/src/ThemeEditor.ViewModels/Extensions.cs @@ -9,6 +9,11 @@ namespace ThemeEditor { public static class Extensions { + private static string Invariant(double value) + { + return FormattableString.Invariant($"{value}"); + } + public static IBrush ToBursh(this Color color) { return new SolidColorBrush(color); @@ -72,7 +77,12 @@ namespace ThemeEditor public static string ToTextString(this ThicknessViewModel thickness) { - return $"{thickness.ToThickness()}"; + var t = thickness.ToThickness(); + if (t.IsUniform) + return Invariant(t.Left); + else if (t.Left.Equals(t.Right) && t.Top.Equals(t.Bottom)) + return $"{Invariant(t.Left)} {Invariant(t.Top)}"; + return $"{Invariant(t.Left)},{Invariant(t.Top)},{Invariant(t.Right)},{Invariant(t.Bottom)}"; } public static RgbColorViewModel RgbFromHexString(this string value) @@ -207,14 +217,14 @@ namespace ThemeEditor sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(""); - sb.AppendLine($" {theme.ThemeBorderThickness.ToThickness()}"); - sb.AppendLine($" {FormattableString.Invariant($"{theme.ThemeDisabledOpacity}")}"); + sb.AppendLine($" {theme.ThemeBorderThickness.ToTextString()}"); + sb.AppendLine($" {Invariant(theme.ThemeDisabledOpacity)}"); sb.AppendLine(""); - sb.AppendLine($" {FormattableString.Invariant($"{theme.FontSizeSmall}")}"); - sb.AppendLine($" {FormattableString.Invariant($"{theme.FontSizeNormal}")}"); - sb.AppendLine($" {FormattableString.Invariant($"{theme.FontSizeLarge}")}"); + sb.AppendLine($" {Invariant(theme.FontSizeSmall)}"); + sb.AppendLine($" {Invariant(theme.FontSizeNormal)}"); + sb.AppendLine($" {Invariant(theme.FontSizeLarge)}"); sb.AppendLine(""); - sb.AppendLine($" {FormattableString.Invariant($"{theme.ScrollBarThickness}")}"); + sb.AppendLine($" {Invariant(theme.ScrollBarThickness)}"); sb.AppendLine(" "); sb.AppendLine(""); diff --git a/src/ThemeEditor.ViewModels/Serializer/Converters/ThicknessViewModelConverter.cs b/src/ThemeEditor.ViewModels/Serializer/Converters/ThicknessViewModelConverter.cs index c2f6f56..f50c9cd 100644 --- a/src/ThemeEditor.ViewModels/Serializer/Converters/ThicknessViewModelConverter.cs +++ b/src/ThemeEditor.ViewModels/Serializer/Converters/ThicknessViewModelConverter.cs @@ -16,7 +16,7 @@ namespace ThemeEditor.ViewModels.Serializer.Converters switch (value as ThicknessViewModel) { case ThicknessViewModel thickness: - writer.WriteValue(thickness.ToThickness().ToString()); + writer.WriteValue(thickness.ToTextString()); break; default: throw new NotSupportedException($"The {value.GetType()} type is not supported.");