DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="1.2.6" />

 Result

public static class Result
Represents extension methods for type Result<T>.
using DotNext.Reflection; using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext { public static class Result { public static T? OrNull<T>([In] [System.Runtime.CompilerServices.IsReadOnly] ref Result<T> result) where T : struct { if (!result.TryGet(out T value)) return null; return value; } [return: System.Runtime.CompilerServices.IsReadOnly] public static ref Result<T> Coalesce<T>([In] [System.Runtime.CompilerServices.IsReadOnly] ref Result<T> first, [In] [System.Runtime.CompilerServices.IsReadOnly] ref Result<T> second) { if (!first.IsSuccessful) return ref second; return ref first; } public static bool IsResult(this Type resultType) { return resultType.IsGenericInstanceOf(typeof(Result<>)); } public static Type GetUnderlyingType(Type resultType) { if (!resultType.IsResult()) return null; return resultType.GetGenericArguments()[0]; } } }