Пример #1
0
        public static void ThrowExceptionWhenNotInEnum(string paramName, object value, Type enumType)
        {
            Validators.EnsureValidParamName(paramName);
            Validators.ThrowExceptionWhenIsNull("enumType", (object)enumType);
            Type enumType1 = enumType;
            bool flag      = false;

            if (enumType.IsGenericType)
            {
                if (!enumType.Assembly.FullName.Equals(typeof(Nullable <>).Assembly.FullName) || !enumType.Namespace.Equals(typeof(Nullable <>).Namespace) || !enumType.Name.Equals(typeof(Nullable <>).Name))
                {
                    throw new ArgumentException("enumType debe ser una enumeración", "enumType");
                }
                flag      = true;
                enumType1 = Nullable.GetUnderlyingType(enumType);
            }
            if (!enumType1.IsEnum)
            {
                throw new ArgumentException("enumType debe ser una enumeración", "enumType");
            }
            if (!flag && value == null)
            {
                throw new ArgumentException("El valor de '{0}' no puedo ser nulo si el tipo no es nulable", paramName);
            }
            if (!Enumerable.Any <FlagsAttribute>(Enumerable.OfType <FlagsAttribute>((IEnumerable)enumType1.GetCustomAttributes(false))))
            {
                if (value != null && !Enum.IsDefined(enumType1, value))
                {
                    throw new ArgumentException("El valor de '{0}' no es un valor posible", paramName);
                }
            }
            else
            {
                IEnumerable <long> enumerable = Enumerable.Select <object, long>(Enumerable.Cast <object>((IEnumerable)Enum.GetValues(enumType1)), (Func <object, long>)(x => (long)Convert.ChangeType(x, typeof(long))));
                long num1 = 0;
                long num2 = (long)Convert.ChangeType(value, typeof(long));
                foreach (long num3 in enumerable)
                {
                    if ((num3 & num2) == num3)
                    {
                        num1 += num3;
                    }
                }
                if (num1 != num2)
                {
                    throw new ArgumentException("El valor de '{0}' no es un valor posible", paramName);
                }
            }
        }
Пример #2
0
 public static void ThrowExceptionWhenIsNotHexString(Expression <Func <object> > paramExpression)
 {
     Validators.ThrowExceptionWhenIsNull((Expression <Func <object> >)(() => paramExpression));
     Validators.ThrowExceptionWhenIsNotHexString(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression) as string);
 }
Пример #3
0
 public static void ThrowExceptionWhenIsNotValidIdentifier(Expression <Func <object> > paramExpression)
 {
     Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression);
     Validators.ThrowExceptionWhenIsNotValidIdentifier(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression) as string);
 }
Пример #4
0
 public static void ThrowExceptionWhenIsTooLong(Expression <Func <object> > paramExpression, int maxLength)
 {
     Validators.ThrowExceptionWhenIsNull((Expression <Func <object> >)(() => paramExpression));
     Validators.ThrowExceptionWhenIsNegativeOrZero((Expression <Func <object> >)(() => (object)maxLength));
     Validators.ThrowExceptionWhenIsTooLong(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression) as string, maxLength);
 }
Пример #5
0
 public static void ThrowExceptionWhenIsNotEquals(Expression <Func <object> > paramExpression, object expectedValue)
 {
     Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression);
     Validators.ThrowExceptionWhenIsNotEquals(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression), expectedValue);
 }
Пример #6
0
 public static void ThrowExceptionWhenIsNegative(Expression <Func <object> > paramExpression)
 {
     Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression);
     Validators.ThrowExceptionWhenIsNegative(Validators.GetParamName(paramExpression), (int)Validators.GetParamValue(paramExpression));
 }
Пример #7
0
 public static void ThrowExceptionWhenNotInEnum(Expression <Func <object> > paramExpression, Type enumType)
 {
     Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression);
     Validators.ThrowExceptionWhenNotInEnum(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression), enumType);
 }
Пример #8
0
 public static void ThrowExceptionWhenIsNull(Expression <Func <object> > paramExpression)
 {
     Validators.EnsureValidParamExpression(paramExpression);
     Validators.ThrowExceptionWhenIsNull(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression));
 }