Innovenergy_trunk/csharp/Lib/Utils/NullableUtilsClass.Class.cs

26 lines
726 B
C#

using System.Diagnostics.CodeAnalysis;
namespace InnovEnergy.Lib.Utils;
public static class NullableUtilsClass
{
public static IEnumerable<T> ToEnumerable<T>(this T? t) where T : class
{
if (t is not null)
yield return t;
}
public static T ThrowIfNull<T>(this T? t) where T : class => ThrowIfNull(t, null);
public static T ThrowIfNull<T>(this T? t, String? message) where T : class
{
if (t is null)
throw new NullReferenceException(message);
return t;
}
public static Boolean IsNull<T>([NotNullWhen(returnValue: false)] this T? t) where T : class => t is null;
public static T? As<T>(this Object t) where T : class => t as T;
}