Skip to content

Commit 085aa1e

Browse files
authored
Fix return-type for PossibleInstructionResult of EnumInstructionResult
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.
1 parent 76d5068 commit 085aa1e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using System.Globalization;
89

910
namespace Moryx.ControlSystem.VisualInstructions
1011
{
@@ -24,15 +25,28 @@ public static IReadOnlyList<string> PossibleResults(Type resultEnum, params stri
2425
/// <summary>
2526
/// Determine possible string buttons from enum result
2627
/// </summary>
28+
[Obsolete("Use the 'InstructionResults' method instead!'")]
2729
public static IReadOnlyList<InstructionResult> PossibleInstructionResults(Type resultEnum, params string[] exceptions)
2830
{
2931
return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult
3032
{
31-
Key = pair.Value.ToString("D"),
33+
Key = pair.Value.ToString("D", CultureInfo.InvariantCulture),
3234
DisplayValue = pair.Key
3335
}).ToList();
3436
}
3537

38+
/// <summary>
39+
/// Determine possible string buttons from enum result
40+
/// </summary>
41+
public static InstructionResult[] InstructionResults(Type resultEnum, params string[] exceptions)
42+
{
43+
return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult
44+
{
45+
Key = pair.Value.ToString("D", CultureInfo.InvariantCulture),
46+
DisplayValue = pair.Key
47+
}).ToArray();
48+
}
49+
3650
/// <summary>
3751
/// Parse the given result back to an enum value
3852
/// </summary>
@@ -46,7 +60,7 @@ public static int ResultToEnumValue(Type resultEnum, string result)
4660
/// </summary>
4761
public static int ResultToEnumValue(Type resultEnum, InstructionResult result)
4862
{
49-
return int.Parse(result.Key);
63+
return int.Parse(result.Key, CultureInfo.InvariantCulture);
5064
}
5165

5266
/// <summary>
@@ -79,7 +93,7 @@ public static TEnum ResultToGenericEnumValue<TEnum>(string result)
7993
public static TEnum ResultToGenericEnumValue<TEnum>(InstructionResult result)
8094
where TEnum : Enum
8195
{
82-
var numeric = int.Parse(result.Key);
96+
var numeric = int.Parse(result.Key, CultureInfo.InvariantCulture);
8397
return (TEnum)Enum.ToObject(typeof(TEnum), numeric);
8498
}
8599

0 commit comments

Comments
 (0)