From 4bf295a028e2e381eccc36258d9189de1c5e24f5 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 20 Jul 2021 17:29:57 +0100 Subject: [PATCH] Call generic Enum.Parse for .NET >= 5 --- X10D/src/StringExtensions/StringExtensions.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/X10D/src/StringExtensions/StringExtensions.cs b/X10D/src/StringExtensions/StringExtensions.cs index c62fb9b..93bfd03 100644 --- a/X10D/src/StringExtensions/StringExtensions.cs +++ b/X10D/src/StringExtensions/StringExtensions.cs @@ -136,12 +136,16 @@ namespace X10D throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value)); } +#if NET5_0_OR_GREATER + return Enum.Parse(value, ignoreCase); +#else if (typeof(T) is not { IsEnum: true } type) { throw new ArgumentException(Resource.EnumParseNotEnumException); } return (T)Enum.Parse(type, value, ignoreCase); +#endif } ///