1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:05:42 +00:00

Call generic Enum.Parse<T> for .NET >= 5

This commit is contained in:
Oliver Booth 2021-07-20 17:29:57 +01:00
parent 3bbf689db4
commit 4bf295a028
No known key found for this signature in database
GPG Key ID: A4AC17007530E9B4

View File

@ -136,12 +136,16 @@ namespace X10D
throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value));
}
#if NET5_0_OR_GREATER
return Enum.Parse<T>(value, ignoreCase);
#else
if (typeof(T) is not { IsEnum: true } type)
{
throw new ArgumentException(Resource.EnumParseNotEnumException);
}
return (T)Enum.Parse(type, value, ignoreCase);
#endif
}
/// <summary>