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); } } }
public static void ThrowExceptionWhenIsNotHexString(Expression <Func <object> > paramExpression) { Validators.ThrowExceptionWhenIsNull((Expression <Func <object> >)(() => paramExpression)); Validators.ThrowExceptionWhenIsNotHexString(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression) as string); }
public static void ThrowExceptionWhenIsNotValidIdentifier(Expression <Func <object> > paramExpression) { Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression); Validators.ThrowExceptionWhenIsNotValidIdentifier(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression) as string); }
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); }
public static void ThrowExceptionWhenIsNotEquals(Expression <Func <object> > paramExpression, object expectedValue) { Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression); Validators.ThrowExceptionWhenIsNotEquals(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression), expectedValue); }
public static void ThrowExceptionWhenIsNegative(Expression <Func <object> > paramExpression) { Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression); Validators.ThrowExceptionWhenIsNegative(Validators.GetParamName(paramExpression), (int)Validators.GetParamValue(paramExpression)); }
public static void ThrowExceptionWhenNotInEnum(Expression <Func <object> > paramExpression, Type enumType) { Validators.ThrowExceptionWhenIsNull("paramExpression", (object)paramExpression); Validators.ThrowExceptionWhenNotInEnum(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression), enumType); }
public static void ThrowExceptionWhenIsNull(Expression <Func <object> > paramExpression) { Validators.EnsureValidParamExpression(paramExpression); Validators.ThrowExceptionWhenIsNull(Validators.GetParamName(paramExpression), Validators.GetParamValue(paramExpression)); }