Automatically create IParseable<T> for enums #120558
-
Currently Enum needs to be treated differently when parsing XML content. public static T Parse<T>(string value)
{
if (TryParseInternal<T>(value, out var result, out var exception))
return result;
exception.Throw();
return default;
} where it would be nice to simply express it like public static T Parse<T>(string value) where T : IParseable<T> However it seems that this is currently not possible. If the IL for this enum public enum Test
{
A,
B
} this
would it make sense to automatically implement IParsable and implement the associated methods. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As mentioned at dotnet/csharplang#9747 (comment), currently there's no way to do this at either side. Any API surface implemented "magically" by runtime must have corresponding metadata/contract in order to be understood by languages. |
Beta Was this translation helpful? Give feedback.
As mentioned at dotnet/csharplang#9747 (comment), currently there's no way to do this at either side. Any API surface implemented "magically" by runtime must have corresponding metadata/contract in order to be understood by languages.