Add debugging helper `DescribeIsNull`

This commit is contained in:
YoshiRulz 2023-01-25 01:10:51 +10:00
parent 0b7960ff04
commit 9e8b0c604d
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 16 additions and 0 deletions

View File

@ -78,6 +78,22 @@ namespace BizHawk.Common
return a.All(kvp => b.TryGetValue(kvp.Key, out var bVal) && comparer.Equals(kvp.Value, bVal));
}
#if NET6_0
public static string DescribeIsNull<T>(T? obj, [CallerArgumentExpression("boxed")] string expr = default)
#else
public static string DescribeIsNull<T>(T? obj, string expr)
#endif
where T : class
=> $"{expr} is {(obj is null ? "null" : "not null")}";
#if NET6_0
public static string DescribeIsNullValT<T>(T? boxed, [CallerArgumentExpression("boxed")] string expr = default)
#else
public static string DescribeIsNullValT<T>(T? boxed, string expr)
#endif
where T : struct
=> $"{expr} is {(boxed is null ? "null" : "not null")}";
/// <param name="filesize">in bytes</param>
/// <returns>human-readable filesize (converts units up to tebibytes)</returns>
public static string FormatFileSize(long filesize)