Simplify null-safety checks in GetEnumFromDescription<T : Enum>

This commit is contained in:
YoshiRulz 2021-01-09 05:13:57 +10:00
parent 979afcb54d
commit 5078ac392b
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 2 additions and 3 deletions

View File

@ -62,7 +62,7 @@ namespace BizHawk.Common.ReflectionExtensions
/// <returns>An enum value with the given description attribute, if no suitable description is found then a default value of the enum is returned</returns> /// <returns>An enum value with the given description attribute, if no suitable description is found then a default value of the enum is returned</returns>
/// <remarks>implementation from https://stackoverflow.com/a/4367868/7467292</remarks> /// <remarks>implementation from https://stackoverflow.com/a/4367868/7467292</remarks>
public static T GetEnumFromDescription<T>(this string description) public static T GetEnumFromDescription<T>(this string description)
where T : Enum where T : struct, Enum
{ {
var type = typeof(T); var type = typeof(T);
@ -85,8 +85,7 @@ namespace BizHawk.Common.ReflectionExtensions
} }
} }
var def = default(T); // does anyone know why Roslyn thinks this can evaluate to null? --yoshi return default(T);
return def ?? throw new NullReferenceException();
} }
/// <summary> /// <summary>