Add helper in EnumSingleTypeConverter to get enum names as array (#17785)

This commit is contained in:
Frode Flaten
2025-01-03 01:08:23 +05:00
committed by GitHub
parent 61e9f5dcc2
commit c0d7fb787f
2 changed files with 9 additions and 3 deletions
@@ -7705,9 +7705,7 @@ namespace System.Management.Automation
bool withColon = wordToComplete.EndsWith(':');
wordToComplete = withColon ? wordToComplete.Remove(wordToComplete.Length - 1) : wordToComplete;
string enumString = LanguagePrimitives.EnumSingleTypeConverter.EnumValues(typeof(SwitchFlags));
string separator = CultureInfo.CurrentUICulture.TextInfo.ListSeparator;
string[] enumArray = enumString.Split(separator, StringSplitOptions.RemoveEmptyEntries);
string[] enumArray = LanguagePrimitives.EnumSingleTypeConverter.GetEnumNames(typeof(SwitchFlags));
var pattern = WildcardPattern.Get(wordToComplete + "*", WildcardOptions.IgnoreCase);
var enumList = new List<string>();
@@ -2077,6 +2077,14 @@ namespace System.Management.Automation
return string.Join(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, enumHashEntry.names);
}
/// <summary>
/// Returns all names for the provided enum type.
/// </summary>
/// <param name="enumType">The enum type to retrieve names from.</param>
/// <returns>Array of enum names for the specified type.</returns>
internal static string[] GetEnumNames(Type enumType)
=> EnumSingleTypeConverter.GetEnumHashEntry(enumType).names;
/// <summary>
/// Returns all values for the provided enum type.
/// </summary>