-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Runtime
Milestone
Description
Although the Enum.TryParse method (https://msdn.microsoft.com/en-us/library/system.enum.tryparse(v=vs.110).aspx) has two generic overloads, the Enum.Parse overloads (https://msdn.microsoft.com/en-us/library/System.Enum.Parse(v=vs.110).aspx) were added to the .NET Framework in version 1.0, before the introduction of generics. They create the need for rather redundant code, such as
Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString);
which entails the need to add an additional cast, as well as instantiate a Type object that represents the enumeration type.
It would be nice to add generic Parse overloads that correspond to the generic TryParse overloads:
public static TEnum Enum.Parse<TEnum>(String value);
public static TEnum Enum.Parse<TEnum>(String value, Boolean ignoreCase);
Note that there's also another open issue on improving the performance of Enum.TryParse at https://github.com/dotnet/corefx/issues/594.
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Runtime