Пример #1
0
        internal static void ValidateConstant(TypeUsage constantType, object value)
        {
            ArgumentValidation.CheckType(constantType, nameof(constantType));
            EnumType type1;

            if (TypeHelpers.TryGetEdmType <EnumType>(constantType, out type1))
            {
                Type clrEquivalentType = type1.UnderlyingType.ClrEquivalentType;
                if (clrEquivalentType != value.GetType() && (!value.GetType().IsEnum() || !ArgumentValidation.ClrEdmEnumTypesMatch(type1, value.GetType())))
                {
                    throw new ArgumentException(Strings.Cqt_Constant_ClrEnumTypeDoesNotMatchEdmEnumType((object)value.GetType().Name, (object)type1.Name, (object)clrEquivalentType.Name), nameof(value));
                }
            }
            else
            {
                PrimitiveType type2;
                if (!TypeHelpers.TryGetEdmType <PrimitiveType>(constantType, out type2))
                {
                    throw new ArgumentException(Strings.Cqt_Constant_InvalidConstantType((object)constantType.ToString()), nameof(constantType));
                }
                PrimitiveTypeKind primitiveTypeKind;
                if ((!ArgumentValidation.TryGetPrimitiveTypeKind(value.GetType(), out primitiveTypeKind) || type2.PrimitiveTypeKind != primitiveTypeKind) && (!Helper.IsGeographicType(type2) || primitiveTypeKind != PrimitiveTypeKind.Geography) && (!Helper.IsGeometricType(type2) || primitiveTypeKind != PrimitiveTypeKind.Geometry))
                {
                    throw new ArgumentException(Strings.Cqt_Constant_InvalidValueForType((object)constantType.ToString()), nameof(value));
                }
            }
        }