namespace FoodsharingSiegen.Contracts { #region OperationResult //////////////////////////////////////////////////////////////////////////////////////////////////// /// Encapsulates the result of an operation. /// /// A Beging, 20.10.2021. /// /// Generic type parameter. //////////////////////////////////////////////////////////////////////////////////////////////////// public class OperationResult { #region Public Properties //////////////////////////////////////////////////////////////////////////////////////////////////// /// Gets or sets the exception. /// /// The exception. //////////////////////////////////////////////////////////////////////////////////////////////////// public Exception? Exception { get; set; } /// Returns an error message if the exception is set public string ErrorMessage { get { if (Success) return string.Empty; return Exception != null ? Exception.GetBaseException().Message : "Fehler"; } } //////////////////////////////////////////////////////////////////////////////////////////////////// /// Gets or sets a value indicating whether the success. /// /// True if success, false if not. //////////////////////////////////////////////////////////////////////////////////////////////////// public bool Success { get; set; } = true; //////////////////////////////////////////////////////////////////////////////////////////////////// /// Gets or sets the data. /// /// The data. //////////////////////////////////////////////////////////////////////////////////////////////////// public T? Data { get; set; } #endregion Public Properties #region Constructors //////////////////////////////////////////////////////////////////////////////////////////////////// /// Constructor. /// /// A Beging, 20.10.2021. /// /// The exception. //////////////////////////////////////////////////////////////////////////////////////////////////// public OperationResult(Exception exception) { Success = false; Exception = exception; } //////////////////////////////////////////////////////////////////////////////////////////////////// /// Constructor. /// /// A Beging, 20.10.2021. /// /// The data. //////////////////////////////////////////////////////////////////////////////////////////////////// public OperationResult(T data) { Data = data; } //////////////////////////////////////////////////////////////////////////////////////////////////// /// Default constructor. /// /// A Beging, 22.10.2021. //////////////////////////////////////////////////////////////////////////////////////////////////// public OperationResult() { } #endregion Constructors } #endregion OperationResult #region OperationResult //////////////////////////////////////////////////////////////////////////////////////////////////// /// Encapsulates the result of an operation. /// /// A Beging, 20.10.2021. //////////////////////////////////////////////////////////////////////////////////////////////////// public class OperationResult : OperationResult { #region Constructors //////////////////////////////////////////////////////////////////////////////////////////////////// /// Constructor. /// /// A Beging, 20.10.2021. /// /// The exception. //////////////////////////////////////////////////////////////////////////////////////////////////// public OperationResult(Exception exception) : base(exception) { } //////////////////////////////////////////////////////////////////////////////////////////////////// /// Constructor. /// /// A Beging, 20.10.2021. /// /// True to data. //////////////////////////////////////////////////////////////////////////////////////////////////// public OperationResult(bool data) : base(data) { } //////////////////////////////////////////////////////////////////////////////////////////////////// /// Default constructor. /// /// A Beging, 22.10.2021. //////////////////////////////////////////////////////////////////////////////////////////////////// public OperationResult() { } #endregion Constructors } #endregion OperationResult }