| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using Quadarax.Foundation.Core.Value.Extensions;
- namespace Quadarax.Foundation.Core.Data
- {
- public class Result : IResult
- {
- #region *** Properties ***
- public bool IsSuccess { get; protected set; }
- public IEnumerable<IError> Errors => _errors;
- public static IResult Ok => new Result();
- public static IResult Fail => new Result(false, new List<IError> { new Error("Operation failed", 0, ErrorLevelEnum.Error) });
- #endregion
- #region *** Private Fields ***
- private readonly IList<IError> _errors = new List<IError>();
- #endregion
- #region *** Constructors ***
- public Result() : this(true, null)
- {
- }
- public Result(IEnumerable<IError> errors) : this(false, errors)
- {
- }
- public Result(bool isSuccess, IEnumerable<IError>? errors)
- {
- errors ??= new List<IError>();
- IsSuccess = isSuccess;
- _errors.AddRange(errors);
- }
- #endregion
- #region *** Operations ***
- public void SetSuccess(bool isSuccess)
- {
- IsSuccess = isSuccess;
- }
- public void AddError(IError error)
- {
- if (error == null)
- throw new ArgumentNullException(nameof(error));
- _errors.Add(error);
- }
- public void ClearErrors()
- {
- _errors.Clear();
- }
- public object? GetValue()
- {
- return null;
- }
- #endregion
- }
- }
|