<commit_before>﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Abc.Zebus.Util.Extensions;

namespace Abc.Zebus
{
    public class DomainException : Exception
    {
        public int ErrorCode { get; private set; }

        public DomainException(int errorCode, string message, params object[] values)
            : base(string.Format(message, values))
        {
            ErrorCode = errorCode;
        }

        public DomainException(Enum enumVal, params object[] values)
            : this (Convert.ToInt32(enumVal), enumVal.GetAttributeDescription(), values)
        {
        }

        public DomainException(Expression<Func<int>> errorCodeExpression, params object[] values)
            : this (errorCodeExpression.Compile()(), ReadDescriptionFromAttribute(errorCodeExpression), values)
   
        {
        }

        static string ReadDescriptionFromAttribute(Expression<Func<int>> errorCodeExpression)
        {
            var memberExpr = errorCodeExpression.Body as MemberExpression;
            if (memberExpr == null)
                return string.Empty;

            var attr = (DescriptionAttribute)memberExpr.Member.GetCustomAttributes(typeof(DescriptionAttribute)).FirstOrDefault();

            return attr != null ? attr.Description : string.Empty;
        }
    }
}<commit_msg>Allow to set an inner exception in a DomainException<commit_after>﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Abc.Zebus.Util.Extensions;

namespace Abc.Zebus
{
    public class DomainException : Exception
    {
        public int ErrorCode { get; private set; }

        public DomainException(Exception innerException, int errorCode, string message)
            : base(message, innerException)
        {
            ErrorCode = errorCode;
        }

        public DomainException(int errorCode, string message)
            : this(null, errorCode, message)
        {
        }

        public DomainException(int errorCode, string message, params object[] values)
            : this(errorCode, string.Format(message, values))
        {
        }

        public DomainException(Enum enumVal, params object[] values)
            : this(Convert.ToInt32(enumVal), enumVal.GetAttributeDescription(), values)
        {
        }

        public DomainException(Expression<Func<int>> errorCodeExpression, params object[] values)
            : this(errorCodeExpression.Compile()(), ReadDescriptionFromAttribute(errorCodeExpression), values)

        {
        }

        private static string ReadDescriptionFromAttribute(Expression<Func<int>> errorCodeExpression)
        {
            var memberExpr = errorCodeExpression.Body as MemberExpression;
            if (memberExpr == null)
                return string.Empty;

            var attr = (DescriptionAttribute)memberExpr.Member.GetCustomAttributes(typeof(DescriptionAttribute)).FirstOrDefault();

            return attr != null ? attr.Description : string.Empty;
        }
    }
}
{'fraction_non_alphanumeric': 0.08624031007751938, 'fraction_numerical': 0.0012919896640826874, 'mean_word_length': 2.753939393939394, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1664433', 'n_tokens_mistral': 770, 'n_tokens_neox': 742, 'n_words': 181}