Skip to content

Commit

Permalink
Merge pull request #5207 from smoogipoo/nullable-support
Browse files Browse the repository at this point in the history
Add IsNull()/IsNotNull() helper extensions
  • Loading branch information
peppy authored May 29, 2022
2 parents 38d1b7f + 635f9ae commit 55ab9a1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions osu.Framework/Extensions/ObjectExtensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics;

#nullable enable

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace osu.Framework.Extensions.ObjectExtensions
{
/// <summary>
Expand All @@ -27,5 +28,15 @@ public static T AsNonNull<T>(this T? obj)
Debug.Assert(obj != null);
return obj;
}

/// <summary>
/// If the given object is null.
/// </summary>
public static bool IsNull<T>([NotNullWhen(false)] this T obj) => ReferenceEquals(obj, null);

/// <summary>
/// <c>true</c> if the given object is not null, <c>false</c> otherwise.
/// </summary>
public static bool IsNotNull<T>([NotNullWhen(true)] this T obj) => !ReferenceEquals(obj, null);
}
}

0 comments on commit 55ab9a1

Please sign in to comment.