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:
parent
3bbf689db4
commit
4bf295a028
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user