Esempio n. 1
0
 /// <summary>
 /// Verifies that an argument type is assignable from the provided type (meaning
 /// interfaces are implemented, or classes exist in the base class hierarchy).
 /// </summary>
 /// <param name="assignee">The argument type.</param>
 /// <param name="providedType">The type it must be assignable from.</param>
 /// <param name="argumentName">The argument name.</param>
 public static void TypeIsAssignableFromType(Type assignee, Type providedType, string argumentName)
 {
     if (!providedType.IsAssignableFrom(assignee))
     {
         throw new ArgumentException(I18nString.GetString(Resources.TypeNotCompatible,
                                                          assignee, providedType, argumentName));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Checks an Enum argument to ensure that its value is defined by the specified Enum type.
 /// </summary>
 /// <param name="enumType">The Enum type the value should correspond to.</param>
 /// <param name="value">The value to check for.</param>
 /// <param name="argumentName">The name of the argument holding the value.</param>
 public static void EnumValueIsDefined(Type enumType, object value, string argumentName)
 {
     if (Enum.IsDefined(enumType, value) == false)
     {
         throw new ArgumentException(I18nString.GetString(Resources.InvalidEnumValue,
                                                          argumentName, enumType.ToString()));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Checks a string argument to ensure it isn't null or empty
        /// </summary>
        /// <param name="argumentValue">The argument value to check.</param>
        /// <param name="argumentName">The name of the argument.</param>
        public static void ArgumentNotNullOrEmptyString(string argumentValue, string argumentName)
        {
            ArgumentNotNull(argumentValue, argumentName);

            if (argumentValue.Length == 0)
            {
                throw new ArgumentException(I18nString.GetString(Resources.StringCannotBeEmpty, argumentName));
            }
        }
Esempio n. 4
0
        private static void Raise(IExceptionInfo exceptionInfo)
        {
            if (exceptionInfo == null)
            {
                return;                        // How do you throw an exception in throwing an exception
            }
            System.Exception ex = null;

            switch (exceptionInfo.Layer)
            {
            case Constants.ApplicationLayer.Application:
                ex =
                    new ApplicationException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                             exceptionInfo.InnerException);
                break;

            case Constants.ApplicationLayer.Infrastructure:
                ex =
                    new InfrastructureException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                                exceptionInfo.InnerException);
                break;


            case Constants.ApplicationLayer.DataAccess:
                ex =
                    new DataAccessException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                            exceptionInfo.InnerException);
                break;

            case Constants.ApplicationLayer.BusinessEnitity:
                ex =
                    new BusinessEntityException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                                exceptionInfo.InnerException);
                break;

            case Constants.ApplicationLayer.BusinessLogic:
                ex =
                    new BusinessLogicException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                               exceptionInfo.InnerException, exceptionInfo.Severity);


                break;

            default:
                return;
            }

            if (ex != null)
            {
                throw ex;
            }
        }