public readonly struct Outcome<T> {
private readonly T value;
private readonly string errorMessage
public readonly bool IsSuccess
public static Outcome<T> Of(Func<T> function)
{
if (function == null)
throw new ArgumentNullException(nameof(function));
try
{
var value = function();
if (value == null)
return value == null ? Error("Value cannot be null!") : Success(value);
// throw new ValueIsNullException("Value cannot be null!");
return Success(value);
}
catch (Exception exception)
{
return Error(exception);
}
}
public readonly struct Outcome<T> {
private readonly T value;
private readonly string errorMessage
public readonly bool IsSuccess
public static Outcome<T> Of(Func<T> function)
{
if (function == null)
throw new ArgumentNullException(nameof(function));
try
{
var value = function();
if (value == null)
return value == null ? Error("Value cannot be null!") : Success(value);
// throw new ValueIsNullException("Value cannot be null!");
return Success(value);
}
catch (Exception exception)
{
return Error(exception);
}
}