// (C) Copyright 2019 C-xC-c // This file is part of BantFlags. // BantFlags is licensed under the GNU AGPL Version 3.0 or later. // see the LICENSE file or using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace BantFlags.Data { public struct Result { 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 Pass(T value) => new Result(false, default, value); public static Result Fail(string error) => new Result(true, error, default); } }