Esempio n. 1
0
 private void CreateAndCacheExceptionInstance()
 {
     if (CachedException is null)
     {
         var options = new ExceptionBuildingOptions(TargetType)
                       .AddArg(ExceptionArgConstants.INNER, _innerException, x => x != null)
                       .AddArg(ExceptionArgConstants.INNER_EXCEPTION, _innerException, x => x != null)
                       .AddArg(ExceptionArgConstants.MESSAGE, _message)
                       .AddArg(ExceptionArgConstants.PARAM_NAME, _paramName, x => !string.IsNullOrWhiteSpace(x))
                       .AddArg(ExceptionArgConstants.ACTUAL_VALUE, _actualValue)
                       .AddArg(ExceptionArgConstants.ERROR_CODE, _errorCode);
         CachedException = NTypes.CreateInstance <TException>(options.ExceptionType, options.ArgumentDescriptors);
     }
 }
Esempio n. 2
0
        protected void CreateAndCacheExceptionInstance(Dictionary <string, IArgDescriptionVal> exceptionParams)
        {
            if (CachedException is null)
            {
                var options = new ExceptionBuildingOptions(TargetType, exceptionParams)
                              .AddArg(ExceptionArgConstants.INNER, _innerException, x => x != null)
                              .AddArg(ExceptionArgConstants.INNER_EXCEPTION, _innerException, x => x != null)
                              .AddArg(ExceptionArgConstants.MESSAGE, _message, x => !string.IsNullOrWhiteSpace(x))
                              .AddArg(ExceptionArgConstants.PARAM_NAME, _paramName, x => !string.IsNullOrWhiteSpace(x))
                              .AddArg(ExceptionArgConstants.ACTUAL_VALUE, _actualValue, x => x is not null)
                              .AddArg(ExceptionArgConstants.ERROR_CODE, _errorCode, x => x > 0);

                if (exceptionParams is not null)
                {
                    _additionalOps?.Invoke(exceptionParams, options);
                }
#if !NETFRAMEWORK
                CachedException = TypeVisit.CreateInstance(options.ExceptionType, options.ArgumentDescriptors);
#else
                CachedException = TypeVisit.CreateInstance(options.ExceptionType, options.ArgumentDescriptors.ToArray());
#endif
            }
        }