using System; namespace Sony.Filtr.Functional { public struct Result { public readonly string Error; public Result(string error) { this.Error = error; } public bool Ok { get { return this.Error == null; } } public bool Fail { get { return !this.Ok; } } public static Result Success() { return new Result(null); } public static Result Failure(string error) { return new Result(error); } } public struct Result { public readonly T Value; public readonly Exception Exception; public readonly TimeSpan Duration; private Result(T value, Exception ex, TimeSpan duration) { this.Value = value; this.Duration = duration; this.Exception = ex; } public static Result Success(T value) { return new Result(value, null, default(TimeSpan)); } public static Result FromException(Exception ex) { return new Result(default(T), ex, default(TimeSpan)); } public static Result FromException(Exception ex, TimeSpan duration) { return new Result(default(T), ex, duration); } public bool IsOk => this.Exception == null; public bool IsFailed => !this.IsOk; public static implicit operator Result(T ok) => Result.Success(ok); public static implicit operator Result(Exception error) => Result.FromException(error); } }