Example #1
0
        /// <summary>
        /// Throws arg null instead of arg exception just because of the message created
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        public IAssertionOW <T> ThenThrow(string errorMsg = null, params object[] args)
        {
            if (!True)
            {
                return(this);
            }

            if (errorMsg != null && args != null && args.Length > 0)
            {
                errorMsg = String.Format(CultureInfo.InvariantCulture, errorMsg, args);
            }

            if (Debugger.IsAttached)
            {
                throw new ArgumentNullException("", errorMsg == null ? ToString() : AppendTrace(
                                                    String.Format(CultureInfo.InvariantCulture, errorMsg?.Replace("<name>", "{0}") ?? String.Empty, Name)));
            }
            else
            {
                var lineException = new TypeLessException(AppendTrace(String.Format(CultureInfo.InvariantCulture, errorMsg?.Replace("<name>", "{0}") ?? String.Empty, Name)));
                throw new ArgumentNullException(errorMsg == null ?
                                                ToString() :
                                                String.Format(CultureInfo.InvariantCulture, errorMsg?.Replace("<name>", "{0}") ?? String.Empty, Name), lineException);
            }
        }
Example #2
0
        public IAssertionOW <T> ThenThrow <E>(string errorMsg = null, params object[] args) where E : Exception
        {
            if (!True)
            {
                return(this);
            }

            if (errorMsg != null && args != null && args.Length > 0)
            {
                errorMsg = String.Format(CultureInfo.InvariantCulture, errorMsg, args);
            }

            if (Debugger.IsAttached)
            {
                throw (Exception)Activator.CreateInstance(typeof(E), new object[] { errorMsg == null ? ToString() : AppendTrace(String.Format(CultureInfo.InvariantCulture, errorMsg?.Replace("<name>", "{0}") ?? String.Empty, Name)) });
            }
            else
            {
                var lineException = new TypeLessException(AppendTrace(String.Format(CultureInfo.InvariantCulture, errorMsg?.Replace("<name>", "{0}") ?? String.Empty, Name)));
                throw (Exception)Activator.CreateInstance(typeof(E), new object[] { errorMsg == null ? ToString() : String.Format(CultureInfo.InvariantCulture, errorMsg?.Replace("<name>", "{0}"), Name) ?? String.Empty, lineException });
            }
        }