From ff185c7da9906b5561f5f910da3096a9c48cf86d Mon Sep 17 00:00:00 2001 From: Niklas Hamann Date: Mon, 11 Aug 2025 08:20:26 +0200 Subject: [PATCH 1/2] Fix unexpected return-type for `PossibleInstructionResult` of EnumInstructionResult Added method `InstructionResults()` which returns the same data as `PossibleInstructionResult()` but as an array. Marked the `PossibleInstructionResult()` method as obulete, use `InstructionResults()` instead. --- .../VisualInstructions/EnumInstructionResult.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs b/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs index 605f6c7..27379ba 100644 --- a/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs +++ b/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs @@ -24,6 +24,7 @@ public static IReadOnlyList PossibleResults(Type resultEnum, params stri /// /// Determine possible string buttons from enum result /// + [Obsolete("Use the 'InstructionResults' method instead!'")] public static IReadOnlyList PossibleInstructionResults(Type resultEnum, params string[] exceptions) { return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult @@ -33,6 +34,18 @@ public static IReadOnlyList PossibleInstructionResults(Type r }).ToList(); } + /// + /// Determine possible string buttons from enum result + /// + public static InstructionResult[] InstructionResults(Type resultEnum, params string[] exceptions) + { + return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult + { + Key = pair.Value.ToString("D"), + DisplayValue = pair.Key + }).ToArray(); + } + /// /// Parse the given result back to an enum value /// From e5557f60f760ef1d354e8d26012da03732791151 Mon Sep 17 00:00:00 2001 From: Niklas Hamann Date: Tue, 14 Oct 2025 10:11:51 +0200 Subject: [PATCH 2/2] Address review comments - using invariant culture when parsing values to string --- .../VisualInstructions/EnumInstructionResult.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs b/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs index 27379ba..c8627a6 100644 --- a/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs +++ b/src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Globalization; namespace Moryx.ControlSystem.VisualInstructions { @@ -29,7 +30,7 @@ public static IReadOnlyList PossibleInstructionResults(Type r { return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult { - Key = pair.Value.ToString("D"), + Key = pair.Value.ToString("D", CultureInfo.InvariantCulture), DisplayValue = pair.Key }).ToList(); } @@ -41,7 +42,7 @@ public static InstructionResult[] InstructionResults(Type resultEnum, params str { return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult { - Key = pair.Value.ToString("D"), + Key = pair.Value.ToString("D", CultureInfo.InvariantCulture), DisplayValue = pair.Key }).ToArray(); } @@ -59,7 +60,7 @@ public static int ResultToEnumValue(Type resultEnum, string result) /// public static int ResultToEnumValue(Type resultEnum, InstructionResult result) { - return int.Parse(result.Key); + return int.Parse(result.Key, CultureInfo.InvariantCulture); } /// @@ -92,7 +93,7 @@ public static TEnum ResultToGenericEnumValue(string result) public static TEnum ResultToGenericEnumValue(InstructionResult result) where TEnum : Enum { - var numeric = int.Parse(result.Key); + var numeric = int.Parse(result.Key, CultureInfo.InvariantCulture); return (TEnum)Enum.ToObject(typeof(TEnum), numeric); }