using System; namespace DiscordBotCore.Others; public class Result { private bool? _Result; private Exception? Exception { get; } private Result(Exception exception) { _Result = null; Exception = exception; } private Result(bool result) { _Result = result; Exception = null; } public static Result Success() => new Result(true); public static Result Failure(Exception ex) => new Result(ex); public static Result Failure(string message) => new Result(new Exception(message)); public void Match(Action successAction, Action exceptionAction) { if (_Result.HasValue && _Result.Value) { successAction(); } else { exceptionAction(Exception!); } } } public class Result { private readonly OneOf _Result; private Result(OneOf result) { _Result = result; } public static Result From (T value) => new Result(new OneOf(value)); public static implicit operator Result(Exception exception) => new Result(new OneOf(exception)); public void Match(Action valueAction, Action exceptionAction) { _Result.Match(valueAction, exceptionAction); } public TResult Match(Func valueFunc, Func exceptionFunc) { return _Result.Match(valueFunc, exceptionFunc); } }