You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bantflags/BantFlags/Data/ResultT.cs

29 lines
734 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BantFlags.Data
{
public struct Result<T>
{
public bool Failed { get; private set; }
public string ErrorMessage { get; private set; }
private T _Value { get; set; }
public T Value => Failed ? throw new Exception() : _Value;
public Result(bool failed, string error, T value)
{
Failed = failed;
ErrorMessage = error;
_Value = value;
}
public static Result<T> Pass(T value) => new Result<T>(false, default, value);
public static Result<T> Fail(string error) => new Result<T>(true, error, default);
}
}