Beispiel #1
0
        internal static bool TryCastPrimitiveAsType(this IEdmPrimitiveValue expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors)
        {
            if (!type.IsPrimitive())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.PrimitiveConstantExpressionNotValidForNonPrimitiveType, Edm.Strings.EdmModel_Validator_Semantic_PrimitiveConstantExpressionNotValidForNonPrimitiveType) };
                return(false);
            }

            switch (expression.ValueKind)
            {
            case EdmValueKind.Binary:
                return(TryCastBinaryConstantAsType((IEdmBinaryConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Boolean:
                return(TryCastBooleanConstantAsType((IEdmBooleanConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.DateTimeOffset:
                return(TryCastDateTimeOffsetConstantAsType((IEdmDateTimeOffsetConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Decimal:
                return(TryCastDecimalConstantAsType((IEdmDecimalConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Floating:
                return(TryCastFloatingConstantAsType((IEdmFloatingConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Guid:
                return(TryCastGuidConstantAsType((IEdmGuidConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Integer:
                return(TryCastIntegerConstantAsType((IEdmIntegerConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.String:
                return(TryCastStringConstantAsType((IEdmStringConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Duration:
                return(TryCastDurationConstantAsType((IEdmDurationConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.Date:
                return(TryCastDateConstantAsType((IEdmDateConstantExpression)expression, type, out discoveredErrors));

            case EdmValueKind.TimeOfDay:
                return(TryCastTimeOfDayConstantAsType((IEdmTimeOfDayConstantExpression)expression, type, out discoveredErrors));

            default:
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                return(false);
            }
        }
Beispiel #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);
            }
        }