Add Enum constraint to string.EnumParse<T>

This commit is contained in:
Oliver Booth 2021-07-20 17:29:26 +01:00
parent af3dfaa623
commit 3bbf689db4
No known key found for this signature in database
GPG Key ID: A4AC17007530E9B4
1 changed files with 2 additions and 0 deletions

View File

@ -105,6 +105,7 @@ namespace X10D
/// (http://geekswithblogs.net/sdorman/Default.aspx). /// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks> /// </remarks>
public static T EnumParse<T>(this string value) public static T EnumParse<T>(this string value)
where T : struct, Enum
{ {
return value.EnumParse<T>(false); return value.EnumParse<T>(false);
} }
@ -121,6 +122,7 @@ namespace X10D
/// (http://geekswithblogs.net/sdorman/Default.aspx). /// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks> /// </remarks>
public static T EnumParse<T>(this string value, bool ignoreCase) public static T EnumParse<T>(this string value, bool ignoreCase)
where T : struct, Enum
{ {
if (value is null) if (value is null)
{ {