Beispiel #1
0
 private static bool TryAssertBinaryConstantAsType(IEdmBinaryConstantExpression expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors)
 {
     if (type.IsBinary())
     {
         IEdmBinaryTypeReference edmBinaryTypeReference = type.AsBinary();
         int?maxLength = edmBinaryTypeReference.MaxLength;
         if (maxLength.HasValue)
         {
             int?nullable = edmBinaryTypeReference.MaxLength;
             if ((int)expression.Value.Length > nullable.Value)
             {
                 EdmError[] edmError   = new EdmError[1];
                 int?       maxLength1 = edmBinaryTypeReference.MaxLength;
                 edmError[0]      = new EdmError(expression.Location(), EdmErrorCode.BinaryConstantLengthOutOfRange, Strings.EdmModel_Validator_Semantic_BinaryConstantLengthOutOfRange((int)expression.Value.Length, maxLength1.Value));
                 discoveredErrors = edmError;
                 return(false);
             }
         }
         discoveredErrors = Enumerable.Empty <EdmError>();
         return(true);
     }
     else
     {
         EdmError[] edmErrorArray = new EdmError[1];
         edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
         discoveredErrors = edmErrorArray;
         return(false);
     }
 }
Beispiel #2
0
        private static bool TryAssertBinaryConstantAsType(IEdmBinaryConstantExpression expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors)
        {
            if (!type.IsBinary())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                return(false);
            }

            IEdmBinaryTypeReference binaryType = type.AsBinary();

            if (binaryType.MaxLength.HasValue && expression.Value.Length > binaryType.MaxLength.Value)
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.BinaryConstantLengthOutOfRange, Edm.Strings.EdmModel_Validator_Semantic_BinaryConstantLengthOutOfRange(expression.Value.Length, binaryType.MaxLength.Value)) };
                return(false);
            }

            discoveredErrors = Enumerable.Empty <EdmError>();
            return(true);
        }
Beispiel #3
0
 protected override void ProcessBinaryConstantExpression(IEdmBinaryConstantExpression expression)
 {
     this.schemaWriter.WriteBinaryConstantExpressionElement(expression);
 }
 internal void WriteBinaryConstantExpressionElement(IEdmBinaryConstantExpression expression)
 {
     this.xmlWriter.WriteStartElement(CsdlConstants.Element_Binary);
     this.xmlWriter.WriteString(EdmValueWriter.BinaryAsXml(expression.Value));
     this.WriteEndElement();
 }
        private static bool TryCastBinaryConstantAsType(IEdmBinaryConstantExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
        {
            if (!type.IsBinary())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                return false;
            }

            IEdmBinaryTypeReference binaryType = type.AsBinary();
            if (binaryType.MaxLength.HasValue && expression.Value.Length > binaryType.MaxLength.Value)
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.BinaryConstantLengthOutOfRange, Edm.Strings.EdmModel_Validator_Semantic_BinaryConstantLengthOutOfRange(expression.Value.Length, binaryType.MaxLength.Value)) };
                return false;
            }

            discoveredErrors = Enumerable.Empty<EdmError>();
            return true;
        }
Beispiel #6
0
 protected virtual void ProcessBinaryConstantExpression(IEdmBinaryConstantExpression expression)
 {
     this.ProcessExpression(expression);
 }
 internal abstract void WriteBinaryConstantExpressionElement(IEdmBinaryConstantExpression expression);
Beispiel #8
0
        /// <summary>
        /// Convert an <see cref="IEdmExpression"/> to a <see cref="ODataValue"/>
        /// </summary>
        /// <param name="expression">The <see cref="IEdmExpression"/>.</param>
        /// <returns>The null or <see cref="ODataValue"/>.</returns>
        public static ODataValue Convert(this IEdmExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            switch (expression.ExpressionKind)
            {
            case EdmExpressionKind.BinaryConstant:
                IEdmBinaryConstantExpression binaryConstant = (IEdmBinaryConstantExpression)expression;
                return(new ODataPrimitiveValue(binaryConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetBinary(false)
                });

            case EdmExpressionKind.BooleanConstant:
                IEdmBooleanConstantExpression booleanConstant = (IEdmBooleanConstantExpression)expression;
                return(new ODataPrimitiveValue(booleanConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetBoolean(false)
                });

            case EdmExpressionKind.DateTimeOffsetConstant:
                IEdmDateTimeOffsetConstantExpression dateTimeOffsetConstant = (IEdmDateTimeOffsetConstantExpression)expression;
                return(new ODataPrimitiveValue(dateTimeOffsetConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDateTimeOffset(false)
                });

            case EdmExpressionKind.DecimalConstant:
                IEdmDecimalConstantExpression decimalConstant = (IEdmDecimalConstantExpression)expression;
                return(new ODataPrimitiveValue(decimalConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDecimal(false)
                });

            case EdmExpressionKind.FloatingConstant:
                IEdmFloatingConstantExpression floatConstant = (IEdmFloatingConstantExpression)expression;
                return(new ODataPrimitiveValue(floatConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDouble(false)
                });

            case EdmExpressionKind.GuidConstant:
                IEdmGuidConstantExpression guidConstant = (IEdmGuidConstantExpression)expression;
                return(new ODataPrimitiveValue(guidConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetGuid(false)
                });

            case EdmExpressionKind.IntegerConstant:
                IEdmIntegerConstantExpression integerConstant = (IEdmIntegerConstantExpression)expression;
                return(new ODataPrimitiveValue(integerConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetInt64(false)
                });

            case EdmExpressionKind.StringConstant:
                IEdmStringConstantExpression stringConstant = (IEdmStringConstantExpression)expression;
                return(new ODataPrimitiveValue(stringConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetString(false)
                });

            case EdmExpressionKind.DurationConstant:
                IEdmDurationConstantExpression durationConstant = (IEdmDurationConstantExpression)expression;
                return(new ODataPrimitiveValue(durationConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDuration(false)
                });

            case EdmExpressionKind.TimeOfDayConstant:
                IEdmTimeOfDayConstantExpression timeOfDayConstant = (IEdmTimeOfDayConstantExpression)expression;
                return(new ODataPrimitiveValue(timeOfDayConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetTimeOfDay(false)
                });

            case EdmExpressionKind.DateConstant:
                IEdmDateConstantExpression dateConstant = (IEdmDateConstantExpression)expression;
                return(new ODataPrimitiveValue(dateConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDate(false)
                });

            case EdmExpressionKind.Record:
                IEdmRecordExpression recordExpression = (IEdmRecordExpression)expression;
                return(new ODataResourceValue
                {
                    TypeReference = recordExpression.DeclaredType,
                    Properties = recordExpression.Properties.ToDictionary(p => p.Name, p => p.Value.Convert())
                });

            case EdmExpressionKind.Collection:
                IEdmCollectionExpression collectionExpression = (IEdmCollectionExpression)expression;
                ODataCollectValue        collectionValue      = new ODataCollectValue
                {
                    TypeReference = collectionExpression.DeclaredType
                };

                collectionValue.Elements = collectionExpression.Elements.Select(e => e.Convert()).ToList();
                return(collectionValue);

            case EdmExpressionKind.Path:
            case EdmExpressionKind.PropertyPath:
            case EdmExpressionKind.NavigationPropertyPath:
            case EdmExpressionKind.EnumMember:
            default:
                throw new NotSupportedException(String.Format(SRResource.NotSupportedEdmExpressionKind, expression.ExpressionKind));
            }
        }
Beispiel #9
0
		private static bool TryAssertBinaryConstantAsType(IEdmBinaryConstantExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
		{
			if (type.IsBinary())
			{
				IEdmBinaryTypeReference edmBinaryTypeReference = type.AsBinary();
				int? maxLength = edmBinaryTypeReference.MaxLength;
				if (maxLength.HasValue)
				{
					int? nullable = edmBinaryTypeReference.MaxLength;
					if ((int)expression.Value.Length > nullable.Value)
					{
						EdmError[] edmError = new EdmError[1];
						int? maxLength1 = edmBinaryTypeReference.MaxLength;
						edmError[0] = new EdmError(expression.Location(), EdmErrorCode.BinaryConstantLengthOutOfRange, Strings.EdmModel_Validator_Semantic_BinaryConstantLengthOutOfRange((int)expression.Value.Length, maxLength1.Value));
						discoveredErrors = edmError;
						return false;
					}
				}
				discoveredErrors = Enumerable.Empty<EdmError>();
				return true;
			}
			else
			{
				EdmError[] edmErrorArray = new EdmError[1];
				edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
				discoveredErrors = edmErrorArray;
				return false;
			}
		}