-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5207 from smoogipoo/nullable-support
Add IsNull()/IsNotNull() helper extensions
- Loading branch information
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
@@ -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); | ||
} | ||
} |