Skip to content

Commit c0d7fb7

Browse files
authored
Add helper in EnumSingleTypeConverter to get enum names as array (#17785)
1 parent 61e9f5d commit c0d7fb7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7705,9 +7705,7 @@ internal static List<CompletionResult> CompleteStatementFlags(TokenKind kind, st
77057705
bool withColon = wordToComplete.EndsWith(':');
77067706
wordToComplete = withColon ? wordToComplete.Remove(wordToComplete.Length - 1) : wordToComplete;
77077707

7708-
string enumString = LanguagePrimitives.EnumSingleTypeConverter.EnumValues(typeof(SwitchFlags));
7709-
string separator = CultureInfo.CurrentUICulture.TextInfo.ListSeparator;
7710-
string[] enumArray = enumString.Split(separator, StringSplitOptions.RemoveEmptyEntries);
7708+
string[] enumArray = LanguagePrimitives.EnumSingleTypeConverter.GetEnumNames(typeof(SwitchFlags));
77117709

77127710
var pattern = WildcardPattern.Get(wordToComplete + "*", WildcardOptions.IgnoreCase);
77137711
var enumList = new List<string>();

src/System.Management.Automation/engine/LanguagePrimitives.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,14 @@ internal static string EnumValues(Type enumType)
20772077
return string.Join(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, enumHashEntry.names);
20782078
}
20792079

2080+
/// <summary>
2081+
/// Returns all names for the provided enum type.
2082+
/// </summary>
2083+
/// <param name="enumType">The enum type to retrieve names from.</param>
2084+
/// <returns>Array of enum names for the specified type.</returns>
2085+
internal static string[] GetEnumNames(Type enumType)
2086+
=> EnumSingleTypeConverter.GetEnumHashEntry(enumType).names;
2087+
20802088
/// <summary>
20812089
/// Returns all values for the provided enum type.
20822090
/// </summary>

0 commit comments

Comments
 (0)