/// <summary>
        ///     Creates an error business result.
        /// </summary>
        /// <param name="exception">The error source exception object, required.</param>
        /// <param name="errorCode">Domain specific error code, optional.</param>
        /// <param name="context">Optional context object for the business process.</param>
        public static BusinessResult <T> Fail(Exception exception, int?errorCode = default(int?), object context = null)
        {
            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            return(new BusinessResult <T>
            {
                Error = BusinessError.FromException(exception, errorCode),
                Context = context,
            });
        }
        /// <summary>
        ///     Creates an error business result.
        /// </summary>
        /// <param name="error">The error object, required.</param>
        /// <param name="context">Optional context object for the business process.</param>
        public static BusinessResult <T> Fail(BusinessError error, object context = null)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            return(new BusinessResult <T>
            {
                Error = error,
                Context = context,
            });
        }
        /// <summary>
        ///     Creates an error business result.
        /// </summary>
        /// <param name="message">The error message, required.</param>
        /// <param name="errorCode">Domain specific error code, optional.</param>
        /// <param name="context">Optional context object for the business process.</param>
        public static BusinessResult <T> Fail(string message, int?errorCode = default(int?), object context = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            return(new BusinessResult <T>
            {
                Error = BusinessError.FromException(new ApplicationException(message), errorCode),
                Context = context,
            });
        }
        /// <summary>
        ///     Creates an instance of the class from an error message text.
        /// </summary>
        /// <param name="errorMessage">The error message, required.</param>
        /// <param name="errorCode">The domain specific error code, optional.</param>
        /// <param name="isFatalError">Specifies if the exception is a fatal one.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown, if the source exception argument 'errorMessage' is NULL.
        /// </exception>
        public static BusinessError FromMessage(string errorMessage, int?errorCode = default(int?), bool?isFatalError = default(bool?))
        {
            if (errorMessage == null)
            {
                throw new ArgumentNullException(nameof(errorMessage));
            }

            var result = new BusinessError
            {
                ErrorCode    = errorCode,
                ErrorMessage = errorMessage,
                IsFatalError = isFatalError
            };

            return(result);
        }
        /// <summary>
        ///     Creates an instance of the class from a source exception object.
        /// </summary>
        /// <param name="e">The exception object, required.</param>
        /// <param name="errorCode">Optionally, the domain specific error code.</param>
        /// <param name="isFatalError">Optionally specifies if the exception is a fatal one.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown, if the source exception argument 'e' is NULL.
        /// </exception>
        public static BusinessError FromException(Exception e, int?errorCode = default(int?), bool?isFatalError = default(bool?))
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var result = new BusinessError
            {
                ErrorCode       = errorCode,
                ErrorMessage    = e.Message,
                IsFatalError    = isFatalError,
                SourceException = e
            };

            result.ErrorInfo.TryAdd(nameof(e.StackTrace), e.StackTrace);

            return(result);
        }