/// <summary> /// Initializes a new instance of the <see cref="Result" /> class. /// </summary> /// <param name="type">The result type.</param> /// <param name="disposition">The disposition.</param> /// <param name="errorMessage">The error message.</param> public Result(ResultType type, Disposition disposition = null, string errorMessage = null) { _dispositions = new List<IDisposition>(); _errorMessages = new List<string>(); Type = type; if (disposition != null) { _dispositions.Add(disposition); } if (!string.IsNullOrWhiteSpace(errorMessage)) { _errorMessages.Add(errorMessage); } }
/// <summary> /// Initializes a new instance of the <see cref="Result" /> class. /// </summary> /// <param name="type">The result type.</param> /// <param name="disposition">The disposition.</param> /// <param name="errorMessage">The error message.</param> public Result(ResultType type, Disposition disposition = null, string errorMessage = null) { _dispositions = new List <IDisposition>(); _errorMessages = new List <string>(); Type = type; if (disposition != null) { _dispositions.Add(disposition); } if (!string.IsNullOrWhiteSpace(errorMessage)) { _errorMessages.Add(errorMessage); } }
/// <summary> /// Creates an outcome for a rule that throws an exception. /// </summary> /// <param name="error">The error.</param> /// <returns> /// The outcome /// </returns> private Result ExceptionOutcome(Exception error) { var builder = new StringBuilder(); while (error != null) { builder.AppendLine(error.Message); error = error.InnerException; } var disposition = new Disposition {Annotation = $"{this} - ERROR (Type Mismatch)", FailureCode = FailureCode}; return new Result(ResultType.Exception, disposition, builder.ToString()); }
/// <summary> /// Returns either a passed or failed outcome based on the specified result /// </summary> /// <param name="result"></param> /// <returns></returns> protected Result BooleanOutcome(bool result) { if (result) return new Result(ResultType.Passed); var disposition = new Disposition { Annotation = $"{this} - FAILED", FailureCode = FailureCode }; return new Result(ResultType.Failed, disposition); }