mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 04:05:40 +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));
|
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)
|
if (typeof(T) is not { IsEnum: true } type)
|
||||||
{
|
{
|
||||||
throw new ArgumentException(Resource.EnumParseNotEnumException);
|
throw new ArgumentException(Resource.EnumParseNotEnumException);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (T)Enum.Parse(type, value, ignoreCase);
|
return (T)Enum.Parse(type, value, ignoreCase);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user