Esempio n. 1
0
        private static bool TryAssertIntegerConstantAsType(IEdmIntegerConstantExpression expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors)
        {
            if (type.IsIntegral())
            {
                EdmPrimitiveTypeKind edmPrimitiveTypeKind = type.PrimitiveKind();
                if (edmPrimitiveTypeKind == EdmPrimitiveTypeKind.Byte)
                {
                    return(ExpressionTypeChecker.TryAssertIntegerConstantInRange(expression, (long)0, (long)0xff, out discoveredErrors));
                }
                else
                {
                    switch (edmPrimitiveTypeKind)
                    {
                    case EdmPrimitiveTypeKind.Int16:
                    {
                        return(ExpressionTypeChecker.TryAssertIntegerConstantInRange(expression, (long)-32768, (long)0x7fff, out discoveredErrors));
                    }

                    case EdmPrimitiveTypeKind.Int32:
                    {
                        return(ExpressionTypeChecker.TryAssertIntegerConstantInRange(expression, (long)-2147483648, (long)0x7fffffff, out discoveredErrors));
                    }

                    case EdmPrimitiveTypeKind.Int64:
                    {
                        return(ExpressionTypeChecker.TryAssertIntegerConstantInRange(expression, -9223372036854775808L, 0x7fffffffffffffffL, out discoveredErrors));
                    }

                    case EdmPrimitiveTypeKind.SByte:
                    {
                        return(ExpressionTypeChecker.TryAssertIntegerConstantInRange(expression, (long)-128, (long)127, out discoveredErrors));
                    }
                    }
                    EdmError[] edmError = new EdmError[1];
                    edmError[0]      = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
                    discoveredErrors = edmError;
                    return(false);
                }
            }
            else
            {
                EdmError[] edmErrorArray = new EdmError[1];
                edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
                discoveredErrors = edmErrorArray;
                return(false);
            }
        }
Esempio n. 2
0
        internal static bool TryAssertPrimitiveAsType(this IEdmPrimitiveValue expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors)
        {
            EdmError[] edmError;
            if (type.IsPrimitive())
            {
                EdmValueKind valueKind = expression.ValueKind;
                switch (valueKind)
                {
                case EdmValueKind.Binary:
                {
                    return(ExpressionTypeChecker.TryAssertBinaryConstantAsType((IEdmBinaryConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Boolean:
                {
                    return(ExpressionTypeChecker.TryAssertBooleanConstantAsType((IEdmBooleanConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Collection:
                case EdmValueKind.Enum:
                case EdmValueKind.Null:
                case EdmValueKind.Structured:
                {
                    edmError         = new EdmError[1];
                    edmError[0]      = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
                    discoveredErrors = edmError;
                    return(false);
                }

                case EdmValueKind.DateTimeOffset:
                {
                    return(ExpressionTypeChecker.TryAssertDateTimeOffsetConstantAsType((IEdmDateTimeOffsetConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.DateTime:
                {
                    return(ExpressionTypeChecker.TryAssertDateTimeConstantAsType((IEdmDateTimeConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Decimal:
                {
                    return(ExpressionTypeChecker.TryAssertDecimalConstantAsType((IEdmDecimalConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Floating:
                {
                    return(ExpressionTypeChecker.TryAssertFloatingConstantAsType((IEdmFloatingConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Guid:
                {
                    return(ExpressionTypeChecker.TryAssertGuidConstantAsType((IEdmGuidConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Integer:
                {
                    return(ExpressionTypeChecker.TryAssertIntegerConstantAsType((IEdmIntegerConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.String:
                {
                    return(ExpressionTypeChecker.TryAssertStringConstantAsType((IEdmStringConstantExpression)expression, type, out discoveredErrors));
                }

                case EdmValueKind.Time:
                {
                    return(ExpressionTypeChecker.TryAssertTimeConstantAsType((IEdmTimeConstantExpression)expression, type, out discoveredErrors));
                }

                default:
                {
                    edmError         = new EdmError[1];
                    edmError[0]      = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
                    discoveredErrors = edmError;
                    return(false);
                }
                }
            }
            else
            {
                EdmError[] edmErrorArray = new EdmError[1];
                edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.PrimitiveConstantExpressionNotValidForNonPrimitiveType, Strings.EdmModel_Validator_Semantic_PrimitiveConstantExpressionNotValidForNonPrimitiveType);
                discoveredErrors = edmErrorArray;
                return(false);
            }
        }
Esempio n. 3
0
 static ExpressionTypeChecker()
 {
     ExpressionTypeChecker.promotionMap = ExpressionTypeChecker.InitializePromotionMap();
 }