From 36bd660a0268c4bc6883b309c788a9857145c26e Mon Sep 17 00:00:00 2001 From: Difegue Date: Sun, 11 Sep 2022 01:15:51 +0200 Subject: [PATCH] Replace EnumToIntConverter with a dumber variant that doesn't set .NET Native on fire god --- .../Strings/Resources.Designer.cs | 45 ------------ .../Strings/Resources.en-US.resx | 20 ------ .../Strings/Resources.fr-FR.resx | 20 ------ .../Strings/Resources.pt-PT.resx | 20 ------ .../Strings/Resources.resx | 20 ------ .../Strings/Resources.zh-CN.resx | 20 ------ .../Stylophone/Converters/EnumConverters.cs | 68 ------------------- .../Converters/ThemeToIntConverter.cs | 32 +++++++++ Sources/Stylophone/Stylophone.csproj | 4 +- Sources/Stylophone/Views/SettingsPage.xaml | 11 ++- 10 files changed, 39 insertions(+), 221 deletions(-) delete mode 100644 Sources/Stylophone/Converters/EnumConverters.cs create mode 100644 Sources/Stylophone/Converters/ThemeToIntConverter.cs diff --git a/Sources/Stylophone.Localization/Strings/Resources.Designer.cs b/Sources/Stylophone.Localization/Strings/Resources.Designer.cs index 62c050d..589217c 100644 --- a/Sources/Stylophone.Localization/Strings/Resources.Designer.cs +++ b/Sources/Stylophone.Localization/Strings/Resources.Designer.cs @@ -483,51 +483,6 @@ public static string ErrorUpdatingPlaylist { } } - /// - /// Recherche une chaîne localisée semblable à parameter must be an Enum name!. - /// - public static string ExceptionEnumToBooleanConverterParameterMustBeAnEnumName { - get { - return ResourceManager.GetString("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName", resourceCulture); - } - } - - /// - /// Recherche une chaîne localisée semblable à value must be an Enum!. - /// - public static string ExceptionEnumToBooleanConverterValueMustBeAnEnum { - get { - return ResourceManager.GetString("ExceptionEnumToBooleanConverterValueMustBeAnEnum", resourceCulture); - } - } - - /// - /// Recherche une chaîne localisée semblable à File name is null or empty. Specify a valid file name. - /// - public static string ExceptionSettingsStorageExtensionsFileNameIsNullOrEmpty { - get { - return ResourceManager.GetString("ExceptionSettingsStorageExtensionsFileNameIsNullOrEmpty", resourceCulture); - } - } - - /// - /// Recherche une chaîne localisée semblable à All pages opened in a new window must subscribe to the Released Event.. - /// - public static string ExceptionViewLifeTimeControlMissingReleasedSubscription { - get { - return ResourceManager.GetString("ExceptionViewLifeTimeControlMissingReleasedSubscription", resourceCulture); - } - } - - /// - /// Recherche une chaîne localisée semblable à This view is being disposed.. - /// - public static string ExceptionViewLifeTimeControlViewDisposal { - get { - return ResourceManager.GetString("ExceptionViewLifeTimeControlViewDisposal", resourceCulture); - } - } - /// /// Recherche une chaîne localisée semblable à David Bowie is credited with playing the Stylophone on his 1969 debut hit song "Space Oddity" and also for his 2002 album Heathen track titled "Slip Away," as well as on the song "Heathen (The Rays)".. /// diff --git a/Sources/Stylophone.Localization/Strings/Resources.en-US.resx b/Sources/Stylophone.Localization/Strings/Resources.en-US.resx index be1fcad..b341934 100644 --- a/Sources/Stylophone.Localization/Strings/Resources.en-US.resx +++ b/Sources/Stylophone.Localization/Strings/Resources.en-US.resx @@ -183,26 +183,6 @@ OK - - File name is null or empty. Specify a valid file name - File name is null or empty to save file in settings storage extensions - - - value must be an Enum! - Value must be an Enum in enum to boolean converter - - - parameter must be an Enum name! - Parameter must be an Enum name in enum to boolean converter - - - This view is being disposed. - View disposed - - - All pages opened in a new window must subscribe to the Released Event. - The page is not subscribed to the Released event. - Added to Playlist {0}! diff --git a/Sources/Stylophone.Localization/Strings/Resources.fr-FR.resx b/Sources/Stylophone.Localization/Strings/Resources.fr-FR.resx index fe02e59..eb9d656 100644 --- a/Sources/Stylophone.Localization/Strings/Resources.fr-FR.resx +++ b/Sources/Stylophone.Localization/Strings/Resources.fr-FR.resx @@ -129,26 +129,6 @@ Bibliothèque Navigation view item name for Library - - File name is null or empty. Specify a valid file name - File name is null or empty to save file in settings storage extensions - - - value must be an Enum! - Value must be an Enum in enum to boolean converter - - - parameter must be an Enum name! - Parameter must be an Enum name in enum to boolean converter - - - This view is being disposed. - View disposed - - - All pages opened in a new window must subscribe to the Released Event. - The page is not subscribed to the Released event. - Ajouté à la Playlist {0} ! diff --git a/Sources/Stylophone.Localization/Strings/Resources.pt-PT.resx b/Sources/Stylophone.Localization/Strings/Resources.pt-PT.resx index 369d6ac..92c13b3 100644 --- a/Sources/Stylophone.Localization/Strings/Resources.pt-PT.resx +++ b/Sources/Stylophone.Localization/Strings/Resources.pt-PT.resx @@ -182,26 +182,6 @@ OK - - File name is null or empty. Specify a valid file name - File name is null or empty to save file in settings storage extensions - - - value must be an Enum! - Value must be an Enum in enum to boolean converter - - - parameter must be an Enum name! - Parameter must be an Enum name in enum to boolean converter - - - This view is being disposed. - View disposed - - - All pages opened in a new window must subscribe to the Released Event. - The page is not subscribed to the Released event. - Adicionado na Lista de reprodução {0}! diff --git a/Sources/Stylophone.Localization/Strings/Resources.resx b/Sources/Stylophone.Localization/Strings/Resources.resx index feaf33a..a5fe00b 100644 --- a/Sources/Stylophone.Localization/Strings/Resources.resx +++ b/Sources/Stylophone.Localization/Strings/Resources.resx @@ -183,26 +183,6 @@ OK - - File name is null or empty. Specify a valid file name - File name is null or empty to save file in settings storage extensions - - - value must be an Enum! - Value must be an Enum in enum to boolean converter - - - parameter must be an Enum name! - Parameter must be an Enum name in enum to boolean converter - - - This view is being disposed. - View disposed - - - All pages opened in a new window must subscribe to the Released Event. - The page is not subscribed to the Released event. - Added to Playlist {0}! diff --git a/Sources/Stylophone.Localization/Strings/Resources.zh-CN.resx b/Sources/Stylophone.Localization/Strings/Resources.zh-CN.resx index d5749ab..462f4b6 100644 --- a/Sources/Stylophone.Localization/Strings/Resources.zh-CN.resx +++ b/Sources/Stylophone.Localization/Strings/Resources.zh-CN.resx @@ -183,26 +183,6 @@ - - 文件名为空。请指定有效文件名。 - File name is null or empty to save file in settings storage extensions - - - 值必须为枚举类型。 - Value must be an Enum in enum to boolean converter - - - 参数必须为枚举类型。 - Parameter must be an Enum name in enum to boolean converter - - - 该视图已被释放。 - View disposed - - - 所有在新窗口打开的页面必须订阅 Released 事件。 - The page is not subscribed to the Released event. - 已添加到播放列表“{0}”。 diff --git a/Sources/Stylophone/Converters/EnumConverters.cs b/Sources/Stylophone/Converters/EnumConverters.cs deleted file mode 100644 index 57a14ec..0000000 --- a/Sources/Stylophone/Converters/EnumConverters.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Stylophone.Localization.Strings; -using System; - -using Windows.UI.Xaml.Data; - -namespace Stylophone.Helpers -{ - public class EnumToBooleanConverter : IValueConverter - { - public Type EnumType { get; set; } - - public object Convert(object value, Type targetType, object parameter, string language) - { - if (parameter is string enumString) - { - if (!Enum.IsDefined(EnumType, value)) - { - throw new ArgumentException(Resources.ExceptionEnumToBooleanConverterValueMustBeAnEnum); - } - - var enumValue = Enum.Parse(EnumType, enumString); - - return enumValue.Equals(value); - } - - throw new ArgumentException(Resources.ExceptionEnumToBooleanConverterParameterMustBeAnEnumName); - } - - public object ConvertBack(object value, Type targetType, object parameter, string language) - { - if (parameter is string enumString) - { - return Enum.Parse(EnumType, enumString); - } - - throw new ArgumentException(Resources.ExceptionEnumToBooleanConverterParameterMustBeAnEnumName); - } - } - - public class EnumToIntConverter : IValueConverter - { - public Type EnumType { get; set; } - - public object Convert(object value, Type targetType, object parameter, string language) - { - - if (!Enum.IsDefined(EnumType, value)) - { - throw new ArgumentException(Resources.ExceptionEnumToBooleanConverterValueMustBeAnEnum); - } - - return (int)value; - - throw new ArgumentException(Resources.ExceptionEnumToBooleanConverterParameterMustBeAnEnumName); - } - - public object ConvertBack(object value, Type targetType, object parameter, string language) - { - if (value is int enumInt) - { - // Cast enumInt to EnumType - return Enum.ToObject(EnumType, enumInt); - } - - throw new ArgumentException(Resources.ExceptionEnumToBooleanConverterParameterMustBeAnEnumName); - } - } -} diff --git a/Sources/Stylophone/Converters/ThemeToIntConverter.cs b/Sources/Stylophone/Converters/ThemeToIntConverter.cs new file mode 100644 index 0000000..2fef677 --- /dev/null +++ b/Sources/Stylophone/Converters/ThemeToIntConverter.cs @@ -0,0 +1,32 @@ +using Stylophone.Common.Interfaces; +using Stylophone.Localization.Strings; +using System; + +using Windows.UI.Xaml.Data; + +namespace Stylophone.Helpers +{ + public class ThemeToIntConverter : IValueConverter + { + + public object Convert(object value, Type targetType, object parameter, string language) + { + + if (value is Theme t) + return (int)t; + + throw new ArgumentException("Not a Theme"); + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + if (value is int enumInt) + { + // Cast enumInt to EnumType + return Enum.ToObject(typeof(Theme), enumInt); + } + + throw new ArgumentException("Not an int"); + } + } +} diff --git a/Sources/Stylophone/Stylophone.csproj b/Sources/Stylophone/Stylophone.csproj index 408f721..89186d5 100644 --- a/Sources/Stylophone/Stylophone.csproj +++ b/Sources/Stylophone/Stylophone.csproj @@ -28,7 +28,7 @@ Always x86|x64|arm 0 - 187A5D2AFF2CB3A375B862E45117B9B7DF13CACF + AC6B4D78B6FC1C9719183572B36F08C049AFFB1E True DXFeatureLevel @@ -205,7 +205,7 @@ - + diff --git a/Sources/Stylophone/Views/SettingsPage.xaml b/Sources/Stylophone/Views/SettingsPage.xaml index 438b6a9..a6e1384 100644 --- a/Sources/Stylophone/Views/SettingsPage.xaml +++ b/Sources/Stylophone/Views/SettingsPage.xaml @@ -5,16 +5,15 @@ xmlns:controls="using:Microsoft.UI.Xaml.Controls" xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:helper="using:Stylophone.Helpers" xmlns:local="using:Stylophone.Controls" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:strings="using:Stylophone.Localization.Strings" - xmlns:stylophone="using:Stylophone.Common.Interfaces" + xmlns:helpers="using:Stylophone.Helpers" mc:Ignorable="d"> - - - + + + @@ -174,7 +173,7 @@ - +