A game framework written with osu! in mind.
at master 1.1 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System.Diagnostics; 5 6#nullable enable 7 8namespace osu.Framework.Extensions.ObjectExtensions 9{ 10 /// <summary> 11 /// Extensions that apply to all objects. 12 /// </summary> 13 public static class ObjectExtensions 14 { 15 /// <summary> 16 /// Coerces a nullable object as non-nullable. This is an alternative to the C# 8 null-forgiving operator "<c>!</c>". 17 /// </summary> 18 /// <remarks> 19 /// This should only be used when an assertion or other handling is not a reasonable alternative. 20 /// </remarks> 21 /// <param name="obj">The nullable object.</param> 22 /// <typeparam name="T">The type of the object.</typeparam> 23 /// <returns>The non-nullable object corresponding to <paramref name="obj"/>.</returns> 24 public static T AsNonNull<T>(this T? obj) 25 where T : class 26 { 27 Debug.Assert(obj != null); 28 return obj; 29 } 30 } 31}