From 9e8b0c604df3f09021a93a46fa160e02cb00ee9d Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 25 Jan 2023 01:10:51 +1000 Subject: [PATCH] Add debugging helper `DescribeIsNull` --- src/BizHawk.Common/Util.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/BizHawk.Common/Util.cs b/src/BizHawk.Common/Util.cs index eb28b3a6e1..9f33eaf672 100644 --- a/src/BizHawk.Common/Util.cs +++ b/src/BizHawk.Common/Util.cs @@ -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? obj, [CallerArgumentExpression("boxed")] string expr = default) +#else + public static string DescribeIsNull(T? obj, string expr) +#endif + where T : class + => $"{expr} is {(obj is null ? "null" : "not null")}"; + +#if NET6_0 + public static string DescribeIsNullValT(T? boxed, [CallerArgumentExpression("boxed")] string expr = default) +#else + public static string DescribeIsNullValT(T? boxed, string expr) +#endif + where T : struct + => $"{expr} is {(boxed is null ? "null" : "not null")}"; + /// in bytes /// human-readable filesize (converts units up to tebibytes) public static string FormatFileSize(long filesize)