Innovenergy_trunk/csharp/Lib/Utils/NullableUtils.cs

21 lines
479 B
C#

namespace InnovEnergy.Lib.Utils;
public static class NullableUtils
{
public static T? Nullable<T>(this T t) where T : struct => t;
public static IEnumerable<T> Enumerable<T>(this T? t) where T : struct
{
if (t.HasValue)
yield return t.Value;
}
public static T ThrowIfNull<T>(this T? t, String message) where T:struct
{
if (!t.HasValue)
throw new NullReferenceException(message);
return t.Value;
}
}