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
1 changed files with 4 additions and 0 deletions

View File

@ -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>