mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add helper in EnumSingleTypeConverter to get enum names as array (#17785)
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user