예제 #1
0
        private static IEdmPrimitiveTypeReference Nullable(this IEdmPrimitiveTypeReference typeReference, bool isNullable)
        {
            if (typeReference.IsBinary())
            {
                var binary = typeReference.AsBinary();
                return(new EdmBinaryTypeReference(typeReference.PrimitiveDefinition(), isNullable, binary.IsUnbounded, binary.MaxLength));
            }
            else if (typeReference.IsDecimal())
            {
                var decimalRef = typeReference.AsDecimal();
                return(new EdmDecimalTypeReference(typeReference.PrimitiveDefinition(), isNullable, decimalRef.Precision, decimalRef.Scale));
            }
            else if (typeReference.IsTemporal())
            {
                var temporal = typeReference.AsTemporal();
                return(new EdmTemporalTypeReference(typeReference.PrimitiveDefinition(), isNullable, temporal.Precision));
            }
            else if (typeReference.IsString())
            {
                var stringRef = typeReference.AsString();
                return(new EdmStringTypeReference(typeReference.PrimitiveDefinition(), isNullable, stringRef.IsUnbounded, stringRef.MaxLength, stringRef.IsUnicode));
            }

            return(new EdmPrimitiveTypeReference(typeReference.PrimitiveDefinition(), isNullable));
        }
예제 #2
0
        /// <summary>
        /// Verifies that the given <paramref name="primitiveValue"/> is or can be coerced to <paramref name="expectedTypeReference"/>, and coerces it if necessary.
        /// </summary>
        /// <param name="primitiveValue">An EDM primitive value to verify.</param>
        /// <param name="literalValue">The literal value that was parsed as this primitiveValue.</param>
        /// <param name="model">Model to verify against.</param>
        /// <param name="expectedTypeReference">Expected type reference.</param>
        /// <returns>Coerced version of the <paramref name="primitiveValue"/>.</returns>
        internal static object VerifyAndCoerceUriPrimitiveLiteral(
            object primitiveValue,
            string literalValue,
            IEdmModel model,
            IEdmTypeReference expectedTypeReference)
        {
            ExceptionUtils.CheckArgumentNotNull(primitiveValue, "primitiveValue");
            ExceptionUtils.CheckArgumentNotNull(literalValue, "literalValue");
            ExceptionUtils.CheckArgumentNotNull(model, "model");
            ExceptionUtils.CheckArgumentNotNull(expectedTypeReference, "expectedTypeReference");

            // First deal with null literal
            ODataNullValue nullValue = primitiveValue as ODataNullValue;

            if (nullValue != null)
            {
                if (!expectedTypeReference.IsNullable)
                {
                    throw new ODataException(ODataErrorStrings.ODataUriUtils_ConvertFromUriLiteralNullOnNonNullableType(expectedTypeReference.FullName()));
                }

                return(nullValue);
            }

            // Only other positive case is a numeric primitive that needs to be coerced
            IEdmPrimitiveTypeReference expectedPrimitiveTypeReference = expectedTypeReference.AsPrimitiveOrNull();

            if (expectedPrimitiveTypeReference == null)
            {
                throw new ODataException(ODataErrorStrings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedTypeReference.FullName(), literalValue));
            }

            object coercedResult = CoerceNumericType(primitiveValue, expectedPrimitiveTypeReference.PrimitiveDefinition());

            if (coercedResult != null)
            {
                return(coercedResult);
            }

            // if expectedTypeReference is set, need to coerce cast
            coercedResult = CoerceTemporalType(primitiveValue, expectedPrimitiveTypeReference.PrimitiveDefinition());
            if (coercedResult != null)
            {
                return(coercedResult);
            }

            Type actualType = primitiveValue.GetType();
            Type targetType = TypeUtils.GetNonNullableType(EdmLibraryExtensions.GetPrimitiveClrType(expectedPrimitiveTypeReference));

            // If target type is assignable from actual type, we're OK
            if (targetType.IsAssignableFrom(actualType))
            {
                return(primitiveValue);
            }

            throw new ODataException(ODataErrorStrings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedPrimitiveTypeReference.FullName(), literalValue));
        }
예제 #3
0
 private static IEdmPrimitiveTypeReference CreateTemporalTypeReference(IEdmPrimitiveTypeReference primitiveTypeReference, bool nullableFacet, List <KeyValuePair <string, object> > annotations)
 {
     if (annotations.Count == 0)
     {
         if (primitiveTypeReference.IsNullable != nullableFacet)
         {
             return(new EdmTemporalTypeReference(primitiveTypeReference.PrimitiveDefinition(), nullableFacet));
         }
         return(primitiveTypeReference);
     }
     return(new EdmTemporalTypeReference(primitiveTypeReference.PrimitiveDefinition(), nullableFacet, GetPrecisionAnnotation(annotations)));
 }
예제 #4
0
        private static IEdmPrimitiveTypeReference CreateBinaryTypeReference(IEdmPrimitiveTypeReference primitiveTypeReference, bool nullableFacet, List <KeyValuePair <string, object> > annotations)
        {
            bool flag;

            if (annotations.Count == 0)
            {
                if (primitiveTypeReference.IsNullable != nullableFacet)
                {
                    return(new EdmBinaryTypeReference(primitiveTypeReference.PrimitiveDefinition(), nullableFacet));
                }
                return(primitiveTypeReference);
            }
            int?maxLengthAnnotation = GetMaxLengthAnnotation(annotations, out flag);

            return(new EdmBinaryTypeReference(primitiveTypeReference.PrimitiveDefinition(), nullableFacet, flag, maxLengthAnnotation, GetFixedLengthAnnotation(annotations)));
        }
예제 #5
0
        /// <summary>Gets a flag for the numeric kind of type.</summary>
        /// <param name="typeReference">Type to get numeric kind for.</param>
        /// <returns>The <see cref="NumericTypeKind"/> of the <paramref name="typeReference"/> argument.</returns>
        private static NumericTypeKind GetNumericTypeKind(IEdmTypeReference typeReference)
        {
            IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitiveOrNull();

            if (primitiveTypeReference == null)
            {
                return(NumericTypeKind.NotNumeric);
            }

            switch (primitiveTypeReference.PrimitiveDefinition().PrimitiveKind)
            {
            case EdmPrimitiveTypeKind.Single:
            case EdmPrimitiveTypeKind.Decimal:
            case EdmPrimitiveTypeKind.Double:
                return(NumericTypeKind.NotIntegral);

            case EdmPrimitiveTypeKind.Int16:
            case EdmPrimitiveTypeKind.Int32:
            case EdmPrimitiveTypeKind.Int64:
            case EdmPrimitiveTypeKind.SByte:
                return(NumericTypeKind.SignedIntegral);

            case EdmPrimitiveTypeKind.Byte:
                return(NumericTypeKind.UnsignedIntegral);

            default:
                return(NumericTypeKind.NotNumeric);
            }
        }
예제 #6
0
        /// <summary>
        /// Verifies that the given <paramref name="primitiveValue"/> is or can be coerced to <paramref name="expectedTypeReference"/>, and coerces it if necessary.
        /// </summary>
        /// <param name="primitiveValue">An EDM primitive value to verify.</param>
        /// <param name="model">Model to verify against.</param>
        /// <param name="expectedTypeReference">Expected type reference.</param>
        /// <param name="version">The version to use for reading.</param>
        /// <returns>Coerced version of the <paramref name="primitiveValue"/>.</returns>
        internal static object VerifyAndCoerceUriPrimitiveLiteral(object primitiveValue, IEdmModel model, IEdmTypeReference expectedTypeReference, ODataVersion version)
        {
            DebugUtils.CheckNoExternalCallers();
            ExceptionUtils.CheckArgumentNotNull(primitiveValue, "primitiveValue");
            ExceptionUtils.CheckArgumentNotNull(model, "model");
            ExceptionUtils.CheckArgumentNotNull(expectedTypeReference, "expectedTypeReference");

            // First deal with null literal
            ODataUriNullValue nullValue = primitiveValue as ODataUriNullValue;

            if (nullValue != null)
            {
                if (!expectedTypeReference.IsNullable)
                {
                    throw new ODataException(o.Strings.ODataUriUtils_ConvertFromUriLiteralNullOnNonNullableType(expectedTypeReference.ODataFullName()));
                }

                IEdmType actualResolvedType = ValidationUtils.ValidateValueTypeName(model, nullValue.TypeName, expectedTypeReference.Definition.TypeKind);
                Debug.Assert(actualResolvedType != null, "This is a primitive-only codepath so actualResolvedType != null.");

                if (actualResolvedType.IsSpatial())
                {
                    ODataVersionChecker.CheckSpatialValue(version);
                }

                if (TypePromotionUtils.CanConvertTo(actualResolvedType.ToTypeReference(), expectedTypeReference))
                {
                    nullValue.TypeName = expectedTypeReference.ODataFullName();
                    return(nullValue);
                }

                throw new ODataException(o.Strings.ODataUriUtils_ConvertFromUriLiteralNullTypeVerificationFailure(expectedTypeReference.ODataFullName(), nullValue.TypeName));
            }

            // Only other positive case is a numeric primitive that needs to be coerced
            IEdmPrimitiveTypeReference expectedPrimitiveTypeReference = expectedTypeReference.AsPrimitiveOrNull();

            if (expectedPrimitiveTypeReference == null)
            {
                throw new ODataException(o.Strings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedTypeReference.ODataFullName(), primitiveValue));
            }

            object coercedResult = CoerceNumericType(primitiveValue, expectedPrimitiveTypeReference.PrimitiveDefinition());

            if (coercedResult != null)
            {
                return(coercedResult);
            }

            Type actualType = primitiveValue.GetType();
            Type targetType = TypeUtils.GetNonNullableType(EdmLibraryExtensions.GetPrimitiveClrType(expectedPrimitiveTypeReference));

            // If target type is assignable from actual type, we're OK
            if (targetType.IsAssignableFrom(actualType))
            {
                return(primitiveValue);
            }

            throw new ODataException(o.Strings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedPrimitiveTypeReference.ODataFullName(), primitiveValue));
        }
예제 #7
0
        private static IEdmPrimitiveTypeReference CreateSpatialTypeReference(IEdmPrimitiveTypeReference primitiveTypeReference, bool nullableFacet, List <KeyValuePair <string, object> > annotations)
        {
            object obj2;

            if ((annotations.Count == 0) || !TryFindAndRemoveAnnotation(annotations, "SRID", out obj2))
            {
                if (primitiveTypeReference.IsNullable != nullableFacet)
                {
                    return(new EdmSpatialTypeReference(primitiveTypeReference.PrimitiveDefinition(), nullableFacet, null));
                }
                return(primitiveTypeReference);
            }
            int num = ConvertAnnotationValue <int>(obj2, "SRID");

            return(new EdmSpatialTypeReference(primitiveTypeReference.PrimitiveDefinition(), nullableFacet, new int?(num)));
        }
예제 #8
0
        private static IEdmPrimitiveTypeReference GetPrimitiveTypeReferenceFromTypeAndFacets(Type clrType, List <KeyValuePair <string, object> > annotations)
        {
            IEdmPrimitiveTypeReference primitiveTypeReference = EdmLibraryExtensions.GetPrimitiveTypeReference(clrType);

            if (primitiveTypeReference.IsSpatial())
            {
                primitiveTypeReference = new EdmSpatialTypeReference(primitiveTypeReference.PrimitiveDefinition(), primitiveTypeReference.IsNullable, null);
            }
            return(primitiveTypeReference.ApplyFacetAnnotations(annotations));
        }
        /// <summary>
        /// Create a <see cref="OpenApiSchema"/> for a <see cref="IEdmPrimitiveTypeReference"/>.
        /// </summary>
        /// <param name="context">The OData context.</param>
        /// <param name="primitiveType">The Edm primitive reference.</param>
        /// <returns>The created <see cref="OpenApiSchema"/>.</returns>
        public static OpenApiSchema CreateSchema(this ODataContext context, IEdmPrimitiveTypeReference primitiveType)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(primitiveType, nameof(primitiveType));

            OpenApiSchema schema = context.CreateSchema(primitiveType.PrimitiveDefinition());

            if (schema != null)
            {
                switch (primitiveType.PrimitiveKind())
                {
                case EdmPrimitiveTypeKind.Binary:     // binary
                    IEdmBinaryTypeReference binaryTypeReference = (IEdmBinaryTypeReference)primitiveType;
                    schema.MaxLength = binaryTypeReference.MaxLength;
                    break;

                case EdmPrimitiveTypeKind.Decimal:     // decimal
                    IEdmDecimalTypeReference decimalTypeReference = (IEdmDecimalTypeReference)primitiveType;
                    if (decimalTypeReference.Precision != null)
                    {
                        if (decimalTypeReference.Scale != null)
                        {
                            // The precision is represented with the maximum and minimum keywords and a value of ±(10^ (precision - scale) - 10^ scale).
                            double tmp = Math.Pow(10, decimalTypeReference.Precision.Value - decimalTypeReference.Scale.Value)
                                         - Math.Pow(10, -decimalTypeReference.Scale.Value);
                            schema.Minimum = (decimal?)(tmp * -1.0);
                            schema.Maximum = (decimal?)(tmp);
                        }
                        else
                        {
                            // If the scale facet has a numeric value, and ±(10^precision - 1) if the scale is variable
                            double tmp = Math.Pow(10, decimalTypeReference.Precision.Value) - 1;
                            schema.Minimum = (decimal?)(tmp * -1.0);
                            schema.Maximum = (decimal?)(tmp);
                        }
                    }

                    // The scale of properties of type Edm.Decimal are represented with the OpenAPI Specification keyword multipleOf and a value of 10 ^ -scale
                    schema.MultipleOf = decimalTypeReference.Scale == null ? null : (decimal?)(Math.Pow(10, decimalTypeReference.Scale.Value * -1));
                    break;

                case EdmPrimitiveTypeKind.String:     // string
                    IEdmStringTypeReference stringTypeReference = (IEdmStringTypeReference)primitiveType;
                    schema.MaxLength = stringTypeReference.MaxLength;
                    break;
                }

                // Nullable properties are marked with the keyword nullable and a value of true.
                schema.Nullable = primitiveType.IsNullable ? true : false;
            }

            return(schema);
        }
        /// <summary>
        /// Gets the corresponding <see cref="Type"/> for a given Edm primitive type <see cref="IEdmPrimitiveTypeReference"/>.
        /// </summary>
        /// <param name="mapper">The type mapper.</param>
        /// <param name="primitiveType">The Edm primitive type reference.</param>
        /// <returns>Null or the CLR type.</returns>
        public static Type GetPrimitiveType(this IODataTypeMapper mapper, IEdmPrimitiveTypeReference primitiveType)
        {
            if (mapper == null)
            {
                throw Error.ArgumentNull(nameof(mapper));
            }

            if (primitiveType == null)
            {
                throw Error.ArgumentNull(nameof(primitiveType));
            }

            return(mapper.GetClrPrimitiveType(primitiveType.PrimitiveDefinition(), primitiveType.IsNullable));
        }
예제 #11
0
        internal static bool CanConvertTo(SingleValueNode sourceNodeOrNull, IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
        {
            Debug.Assert(sourceReference != null, "sourceReference != null");
            Debug.Assert(targetReference != null, "targetReference != null");

            //// Copy of the ResourceQueryParser.ExpressionParser.IsCompatibleWith method.

            if (sourceReference.IsEquivalentTo(targetReference))
            {
                return true;
            }

            if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
            {
                // for structured types, use IsAssignableFrom
                return EdmLibraryExtensions.IsAssignableFrom(
                    (IEdmStructuredType)targetReference.Definition,
                    (IEdmStructuredType)sourceReference.Definition);
            }

            //// This rule stops the parser from considering nullable types as incompatible
            //// with non-nullable types. We have however implemented this rule because we just
            //// access underlying rules. C# requires an explicit .Value access, and EDM has no
            //// nullablity on types and (at the model level) implements null propagation.
            ////
            //// if (sourceReference.IsNullable && !targetReference.IsNullable)
            //// {
            ////     return false;
            //// }

            if (sourceReference.IsEnum() && targetReference.IsEnum())
            {
                if (sourceReference.Definition.IsEquivalentTo(targetReference.Definition))
                {
                    return targetReference.IsNullable() || (!sourceReference.IsNullable());
                }

                return false;
            }

            IEdmPrimitiveTypeReference sourcePrimitiveTypeReference = sourceReference.AsPrimitiveOrNull();
            IEdmPrimitiveTypeReference targetPrimitiveTypeReference = targetReference.AsPrimitiveOrNull();

            if (sourcePrimitiveTypeReference == null || targetPrimitiveTypeReference == null)
            {
                return false;
            }

            return MetadataUtilsCommon.CanConvertPrimitiveTypeTo(sourceNodeOrNull, sourcePrimitiveTypeReference.PrimitiveDefinition(), targetPrimitiveTypeReference.PrimitiveDefinition());
        }
        /// <summary>
        /// Gets the corresponding CLR type for a given Edm primitive type.
        /// </summary>
        /// <param name="edmModel">The Edm model.</param>
        /// <param name="edmPrimitiveType">The given Edm primitive type.</param>
        /// <returns>Null or the CLR type.</returns>
        public static Type GetClrPrimitiveType(this IEdmModel edmModel, IEdmPrimitiveTypeReference edmPrimitiveType)
        {
            if (edmPrimitiveType == null)
            {
                return(null);
            }

            if (edmModel == null || edmModel is EdmCoreModel)
            {
                return(DefaultODataTypeMapper.Default.GetClrPrimitiveType(edmPrimitiveType.PrimitiveDefinition(), edmPrimitiveType.IsNullable));
            }

            return(edmModel.GetTypeMapper().GetPrimitiveType(edmPrimitiveType));
        }
예제 #13
0
        private void VisitPrimitiveTypeReference(IEdmPrimitiveTypeReference reference)
        {
            string qualifiedName = reference.FullName();

            if (_types.ContainsKey(qualifiedName))
            {
                return;
            }

            IEdmPrimitiveType primitiveType = reference.PrimitiveDefinition();

            MetaPrimitiveType metaPrimitiveType = new MetaPrimitiveType();

            metaPrimitiveType.QualifiedName = qualifiedName;
            metaPrimitiveType.Name          = primitiveType.Name;
            _types[qualifiedName]           = metaPrimitiveType;
        }
예제 #14
0
 internal static object VerifyAndCoerceUriPrimitiveLiteral(object primitiveValue, IEdmModel model, IEdmTypeReference expectedTypeReference, ODataVersion version)
 {
     ExceptionUtils.CheckArgumentNotNull<object>(primitiveValue, "primitiveValue");
     ExceptionUtils.CheckArgumentNotNull<IEdmModel>(model, "model");
     ExceptionUtils.CheckArgumentNotNull<IEdmTypeReference>(expectedTypeReference, "expectedTypeReference");
     ODataUriNullValue value2 = primitiveValue as ODataUriNullValue;
     if (value2 != null)
     {
         if (!expectedTypeReference.IsNullable)
         {
             throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralNullOnNonNullableType(expectedTypeReference.ODataFullName()));
         }
         IEdmType type = ValidationUtils.ValidateValueTypeName(model, value2.TypeName, expectedTypeReference.Definition.TypeKind);
         if (type.IsSpatial())
         {
             ODataVersionChecker.CheckSpatialValue(version);
         }
         if (!TypePromotionUtils.CanConvertTo(type.ToTypeReference(), expectedTypeReference))
         {
             throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralNullTypeVerificationFailure(expectedTypeReference.ODataFullName(), value2.TypeName));
         }
         value2.TypeName = expectedTypeReference.ODataFullName();
         return value2;
     }
     IEdmPrimitiveTypeReference reference = expectedTypeReference.AsPrimitiveOrNull();
     if (reference == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedTypeReference.ODataFullName(), primitiveValue));
     }
     object obj2 = CoerceNumericType(primitiveValue, reference.PrimitiveDefinition());
     if (obj2 != null)
     {
         return obj2;
     }
     Type c = primitiveValue.GetType();
     if (!TypeUtils.GetNonNullableType(EdmLibraryExtensions.GetPrimitiveClrType(reference)).IsAssignableFrom(c))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(reference.ODataFullName(), primitiveValue));
     }
     return primitiveValue;
 }
예제 #15
0
        /// <summary>
        /// Ensures a primitive type reference for a given primitive type kind.
        /// </summary>
        /// <param name="type">The possibly null type reference.</param>
        /// <param name="primitiveKindFromValue">The primitive type kind to ensure.</param>
        /// <returns>An <see cref="IEdmPrimitiveTypeReference"/> instance created for the <paramref name="primitiveKindFromValue"/>
        /// if <paramref name="type"/> is null; if <paramref name="type"/> is not null, validates it and then returns it.</returns>
        private static IEdmPrimitiveTypeReference EnsurePrimitiveType(IEdmPrimitiveTypeReference type, EdmPrimitiveTypeKind primitiveKindFromValue)
        {
            if (type == null)
            {
                type = EdmCoreModel.Instance.GetPrimitive(primitiveKindFromValue, /*isNullable*/ true);
            }
            else
            {
                EdmPrimitiveTypeKind primitiveKindFromType = type.PrimitiveDefinition().PrimitiveKind;

                if (primitiveKindFromType != primitiveKindFromValue)
                {
                    string typeName = type.FullName();
                    if (typeName == null)
                    {
                        throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKindNoTypeName(primitiveKindFromType.ToString(), primitiveKindFromValue.ToString()));
                    }

                    throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKind(typeName, primitiveKindFromValue.ToString(), primitiveKindFromType.ToString()));
                }
            }

            return(type);
        }
예제 #16
0
        internal static bool CanConvertTo(IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
        {
            if (sourceReference.IsEquivalentTo(targetReference))
            {
                return(true);
            }
            if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
            {
                return(((IEdmStructuredType)targetReference.Definition).IsAssignableFrom(((IEdmStructuredType)sourceReference.Definition)));
            }
            if (IsOpenPropertyType(targetReference))
            {
                return(true);
            }
            IEdmPrimitiveTypeReference type       = sourceReference.AsPrimitiveOrNull();
            IEdmPrimitiveTypeReference reference2 = targetReference.AsPrimitiveOrNull();

            return(((type != null) && (reference2 != null)) && MetadataUtilsCommon.CanConvertPrimitiveTypeTo(type.PrimitiveDefinition(), reference2.PrimitiveDefinition()));
        }
예제 #17
0
        /// <summary>
        /// Converts the given JSON value to the expected type as per OData conversion rules for JSON values.
        /// </summary>
        /// <param name="value">Value to the converted.</param>
        /// <param name="primitiveTypeReference">Type reference to which the value needs to be converted.</param>
        /// <param name="messageReaderSettings">The message reader settings used for reading.</param>
        /// <param name="version">The version of the OData protocol used for reading.</param>
        /// <param name="validateNullValue">true to validate null values; otherwise false.</param>
        /// <returns>Object which is in sync with the property type (modulo the V1 exception of converting numbers to non-compatible target types).</returns>
        internal static object ConvertValue(
            object value,
            IEdmPrimitiveTypeReference primitiveTypeReference,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool validateNullValue)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(primitiveTypeReference != null, "primitiveTypeReference != null");

            //// NOTE: this method was copied from WCF DS (and changed to take a type reference instead of a CLR target type)

            if (value == null)
            {
                // Only primitive type references are validated. Core model is sufficient.
                ReaderValidationUtils.ValidateNullValue(EdmCoreModel.Instance, primitiveTypeReference, messageReaderSettings, validateNullValue, version);
                return(null);
            }

            try
            {
                Type targetType = EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), false);
                ODataReaderBehavior readerBehavior = messageReaderSettings.ReaderBehavior;

                string stringValue = value as string;
                if (stringValue != null)
                {
                    return(ConvertStringValue(stringValue, targetType, version));
                }
                else if (value is Int32)
                {
                    return(ConvertInt32Value((int)value, targetType, primitiveTypeReference, readerBehavior == null ? false : readerBehavior.UseV1ProviderBehavior));
                }
                else if (value is Double)
                {
                    Double doubleValue = (Double)value;
                    if (targetType == typeof(Single))
                    {
                        return(Convert.ToSingle(doubleValue));
                    }

                    if (!IsV1PrimitiveType(targetType) || (targetType != typeof(Double) && (readerBehavior == null || !readerBehavior.UseV1ProviderBehavior)))
                    {
                        throw new ODataException(o.Strings.ODataJsonReaderUtils_CannotConvertDouble(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is bool)
                {
                    if (targetType != typeof(bool) && (readerBehavior == null || readerBehavior.FormatBehaviorKind != ODataBehaviorKind.WcfDataServicesServer))
                    {
                        throw new ODataException(o.Strings.ODataJsonReaderUtils_CannotConvertBoolean(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is DateTime)
                {
                    if (targetType != typeof(DateTime) && (readerBehavior == null || readerBehavior.FormatBehaviorKind != ODataBehaviorKind.WcfDataServicesServer))
                    {
                        throw new ODataException(o.Strings.ODataJsonReaderUtils_CannotConvertDateTime(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is DateTimeOffset)
                {
                    // Currently, we do not support any conversion for DateTimeOffset date type. Hence failing if the target
                    // type is not DateTimeOffset.
                    if (targetType != typeof(DateTimeOffset))
                    {
                        throw new ODataException(o.Strings.ODataJsonReaderUtils_CannotConvertDateTimeOffset(primitiveTypeReference.ODataFullName()));
                    }
                }
            }
            catch (Exception e)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw ReaderValidationUtils.GetPrimitiveTypeConversionException(primitiveTypeReference, e);
            }

            // otherwise just return the value without doing any conversion
            return(value);
        }
예제 #18
0
        /// <summary>
        /// Returns the primitive CLR type for the specified primitive type reference.
        /// </summary>
        /// <param name="primitiveTypeReference">The primitive type to resolve.</param>
        /// <returns>The CLR type for the primitive type reference.</returns>
        internal static Type GetPrimitiveClrType(IEdmPrimitiveTypeReference primitiveTypeReference)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(primitiveTypeReference != null, "primitiveTypeReference != null");

            return GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), primitiveTypeReference.IsNullable); 
        }
예제 #19
0
 internal static Type GetPrimitiveClrType(IEdmPrimitiveTypeReference primitiveTypeReference)
 {
     return(GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), primitiveTypeReference.IsNullable));
 }
예제 #20
0
        private static IEdmPrimitiveTypeReference ApplyFacetAnnotations(this IEdmPrimitiveTypeReference primitiveTypeReference, List <KeyValuePair <string, object> > annotations)
        {
            object obj2;

            if ((annotations == null) || (annotations.Count == 0))
            {
                return(primitiveTypeReference);
            }
            IEdmPrimitiveTypeReference reference = primitiveTypeReference;
            bool isNullable = primitiveTypeReference.IsNullable;

            if (TryFindAndRemoveAnnotation(annotations, "Nullable", out obj2))
            {
                isNullable = ConvertAnnotationValue <bool>(obj2, "Nullable");
            }
            EdmPrimitiveTypeKind kind = primitiveTypeReference.PrimitiveKind();

            switch (kind)
            {
            case EdmPrimitiveTypeKind.Binary:
                return(CreateBinaryTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.Boolean:
            case EdmPrimitiveTypeKind.Byte:
            case EdmPrimitiveTypeKind.Double:
            case EdmPrimitiveTypeKind.Guid:
            case EdmPrimitiveTypeKind.Int16:
            case EdmPrimitiveTypeKind.Int32:
            case EdmPrimitiveTypeKind.Int64:
            case EdmPrimitiveTypeKind.SByte:
            case EdmPrimitiveTypeKind.Single:
            case EdmPrimitiveTypeKind.Stream:
                if (primitiveTypeReference.IsNullable != isNullable)
                {
                    reference = new EdmPrimitiveTypeReference(primitiveTypeReference.PrimitiveDefinition(), isNullable);
                }
                return(reference);

            case EdmPrimitiveTypeKind.DateTime:
            case EdmPrimitiveTypeKind.DateTimeOffset:
            case EdmPrimitiveTypeKind.Time:
                return(CreateTemporalTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.Decimal:
                return(CreateDecimalTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.String:
                return(CreateStringTypeReference(primitiveTypeReference, isNullable, annotations));

            case EdmPrimitiveTypeKind.Geography:
            case EdmPrimitiveTypeKind.GeographyPoint:
            case EdmPrimitiveTypeKind.GeographyLineString:
            case EdmPrimitiveTypeKind.GeographyPolygon:
            case EdmPrimitiveTypeKind.GeographyCollection:
            case EdmPrimitiveTypeKind.GeographyMultiPolygon:
            case EdmPrimitiveTypeKind.GeographyMultiLineString:
            case EdmPrimitiveTypeKind.GeographyMultiPoint:
            case EdmPrimitiveTypeKind.Geometry:
            case EdmPrimitiveTypeKind.GeometryPoint:
            case EdmPrimitiveTypeKind.GeometryLineString:
            case EdmPrimitiveTypeKind.GeometryPolygon:
            case EdmPrimitiveTypeKind.GeometryCollection:
            case EdmPrimitiveTypeKind.GeometryMultiPolygon:
            case EdmPrimitiveTypeKind.GeometryMultiLineString:
            case EdmPrimitiveTypeKind.GeometryMultiPoint:
                return(CreateSpatialTypeReference(primitiveTypeReference, isNullable, annotations));
            }
            throw new InvalidOperationException(System.Data.Services.Strings.MetadataProviderUtils_UnsupportedPrimitiveTypeKind(kind.ToString()));
        }
        /// <summary>
        /// Converts the given payload value to the type defined in a type definition.
        /// </summary>
        /// <param name="value">The given payload value.</param>
        /// <param name="edmTypeReference">The expected type reference from model.</param>
        /// <returns>The converted value of the type.</returns>
        public virtual object ConvertFromPayloadValue(object value, IEdmTypeReference edmTypeReference)
        {
            IEdmPrimitiveTypeReference primitiveTypeReference = edmTypeReference as IEdmPrimitiveTypeReference;

            Debug.Assert(primitiveTypeReference != null, "primitiveTypeReference != null");
            if (primitiveTypeReference.PrimitiveKind() == EdmPrimitiveTypeKind.PrimitiveType)
            {
                return(value);
            }

            try
            {
                Type targetType = EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), false);

                string stringValue = value as string;
                if (stringValue != null)
                {
                    return(ConvertStringValue(stringValue, targetType));
                }
                else if (value is Int32)
                {
                    return(ConvertInt32Value((int)value, targetType, primitiveTypeReference));
                }
                else if (value is Decimal)
                {
                    Decimal decimalValue = (Decimal)value;
                    if (targetType == typeof(Int64))
                    {
                        return(Convert.ToInt64(decimalValue));
                    }

                    if (targetType == typeof(Double))
                    {
                        return(Convert.ToDouble(decimalValue));
                    }

                    if (targetType == typeof(Single))
                    {
                        return(Convert.ToSingle(decimalValue));
                    }

                    if (targetType != typeof(Decimal))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDecimal(primitiveTypeReference.FullName()));
                    }
                }
                else if (value is Double)
                {
                    Double doubleValue = (Double)value;
                    if (targetType == typeof(Single))
                    {
                        return(Convert.ToSingle(doubleValue));
                    }

                    if (targetType != typeof(Double))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDouble(primitiveTypeReference.FullName()));
                    }
                }
                else if (value is bool)
                {
                    if (targetType != typeof(bool))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertBoolean(primitiveTypeReference.FullName()));
                    }
                }
                else if (value is DateTime)
                {
                    if (targetType != typeof(DateTime))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDateTime(primitiveTypeReference.FullName()));
                    }
                }
                else if (value is DateTimeOffset)
                {
                    if (targetType != typeof(DateTimeOffset))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDateTimeOffset(primitiveTypeReference.FullName()));
                    }
                }
            }
            catch (Exception e)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw ReaderValidationUtils.GetPrimitiveTypeConversionException(primitiveTypeReference, e, value.ToString());
            }

            // otherwise just return the value without doing any conversion
            return(value);
        }
예제 #22
0
        private PrimitiveValue GetValue(IEdmPrimitiveTypeReference edmTypeReference)
        {
            switch (edmTypeReference.PrimitiveDefinition().PrimitiveKind)
            {
            case EdmPrimitiveTypeKind.Binary:
                return(new PrimitiveValue("Edm.Binary", 45).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Boolean:
                return(new PrimitiveValue("Edm.Boolean", false).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Byte:
                return(new PrimitiveValue("Edm.Byte", (byte)1).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.DateTimeOffset:
                return(new PrimitiveValue("Edm.DateTimeOffset", new DateTimeOffset(new DateTime(2013, 10, 17), new TimeSpan(0, 0, 3, 0))).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Decimal:
                return(new PrimitiveValue("Edm.Decimal", (decimal)4.3).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Double:
                return(new PrimitiveValue("Edm.Double", (double)54.3333333333333).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Duration:
                return(new PrimitiveValue("Edm.Duration", new TimeSpan(1, 3, 0, 0)).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Geography:
                return(new PrimitiveValue("Edm.Geography", GeographyFactory.Point(5.3, 3.5).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyPoint:
                return(new PrimitiveValue("Edm.GeographyPoint", GeographyFactory.Point(3.5, 3.55555555).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyPolygon:
                return(new PrimitiveValue("Edm.GeographyPolygon", GeographyFactory.Polygon().Ring(3, 4).Ring(4, 5).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyCollection:
                return(new PrimitiveValue("Edm.GeographyCollection", GeographyFactory.Collection().Point(2, 3).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyLineString:
                return(new PrimitiveValue("Edm.GeographyLineString", GeographyFactory.LineString(5.3, 3.3)).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyMultiLineString:
                return(new PrimitiveValue("Edm.GeographyMultiLineString", GeographyFactory.MultiLineString().LineString(3, 4).LineString(5, 4).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyMultiPoint:
                return(new PrimitiveValue("Edm.GeographyMultiPoint", GeographyFactory.MultiPoint().Point(3, 2).Point(6, 4).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeographyMultiPolygon:
                return(new PrimitiveValue("Edm.GeographyMultiPolygon", GeographyFactory.MultiPolygon().Polygon().Ring(65, 23).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Geometry:
                return(new PrimitiveValue("Edm.Geometry", GeometryFactory.Point(-3, 4, 5, 6)).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryCollection:
                return(new PrimitiveValue("Edm.GeometryCollection", GeometryFactory.Collection().Point(3, 2, 3, null).Point(3, 2, 10, null)).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryLineString:
                return(new PrimitiveValue("Edm.GeometryLineString", GeometryFactory.LineString(4.2, 12.3)).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryMultiLineString:
                return(new PrimitiveValue("Edm.GeometryMultiLineString", GeometryFactory.MultiLineString().LineString(3, 2).LineTo(3, 5).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryMultiPoint:
                return(new PrimitiveValue("Edm.GeometryMultiPoint", GeometryFactory.MultiPoint().Point(3, 2).Point(4.3, 3.9).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryMultiPolygon:
                return(new PrimitiveValue("Edm.GeometryMultiPolygon", GeometryFactory.MultiPolygon().Polygon().Ring(65, 23).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryPoint:
                return(new PrimitiveValue("Edm.GeometryPoint", GeometryFactory.Point(-2.3, 3.9)).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.GeometryPolygon:
                return(new PrimitiveValue("Edm.GeometryPolygon", GeometryFactory.Polygon().Ring(3, 4).Ring(4, 5).Build()).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Guid:
                return(new PrimitiveValue("Edm.Guid", new Guid("00005259-2341-5431-5432-234234234234")).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Int16:
                return(new PrimitiveValue("Edm.Int16", (Int16)6).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Int32:
                return(new PrimitiveValue("Edm.Int32", 12).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Int64:
                return(new PrimitiveValue("Edm.Int64", (Int64)18).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.SByte:
                return(new PrimitiveValue("Edm.SByte", (sbyte)-3).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Single:
                return(new PrimitiveValue("Edm.Single", (Single)5.4).WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.Stream:
                return(new PrimitiveValue("Edm.Stream", "232312").WithTypeAnnotation(edmTypeReference));

            case EdmPrimitiveTypeKind.String:
                return(new PrimitiveValue("Edm.String", "Hello").WithTypeAnnotation(edmTypeReference));

            default:
                throw new NotSupportedException("Primitive type kind not supported, please add new type kind.");
            }
        }
예제 #23
0
        /// <summary>
        /// Ensures a primitive type reference for a given primitive type kind.
        /// </summary>
        /// <param name="type">The possibly null type reference.</param>
        /// <param name="primitiveKindFromValue">The primitive type kind to ensure.</param>
        /// <returns>An <see cref="IEdmPrimitiveTypeReference"/> instance created for the <paramref name="primitiveKindFromValue"/> 
        /// if <paramref name="type"/> is null; if <paramref name="type"/> is not null, validates it and then returns it.</returns>
        private static IEdmPrimitiveTypeReference EnsurePrimitiveType(IEdmPrimitiveTypeReference type, EdmPrimitiveTypeKind primitiveKindFromValue)
        {
            if (type == null)
            {
                type = EdmCoreModel.Instance.GetPrimitive(primitiveKindFromValue, /*isNullable*/ true);
            }
            else
            {
                EdmPrimitiveTypeKind primitiveKindFromType = type.PrimitiveDefinition().PrimitiveKind;

                if (primitiveKindFromType != primitiveKindFromValue)
                {
                    string typeName = type.FullName();
                    if (typeName == null)
                    {
                        throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKindNoTypeName(primitiveKindFromType.ToString(), primitiveKindFromValue.ToString()));
                    }

                    throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKind(typeName, primitiveKindFromValue.ToString(), primitiveKindFromType.ToString()));
                }
            }

            return type;
        }
예제 #24
0
 internal static object ConvertValue(object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool validateNullValue)
 {
     if (value == null)
     {
         ReaderValidationUtils.ValidateNullValue(EdmCoreModel.Instance, primitiveTypeReference, messageReaderSettings, validateNullValue, version);
         return(null);
     }
     try
     {
         Type primitiveClrType = EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), false);
         ODataReaderBehavior readerBehavior = messageReaderSettings.ReaderBehavior;
         string stringValue = value as string;
         if (stringValue != null)
         {
             return(ConvertStringValue(stringValue, primitiveClrType, version));
         }
         if (value is int)
         {
             return(ConvertInt32Value((int)value, primitiveClrType, primitiveTypeReference, (readerBehavior != null) && readerBehavior.UseV1ProviderBehavior));
         }
         if (value is double)
         {
             double num = (double)value;
             if (primitiveClrType == typeof(float))
             {
                 return(Convert.ToSingle(num));
             }
             if (!IsV1PrimitiveType(primitiveClrType) || ((primitiveClrType != typeof(double)) && ((readerBehavior == null) || !readerBehavior.UseV1ProviderBehavior)))
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonReaderUtils_CannotConvertDouble(primitiveTypeReference.ODataFullName()));
             }
             return(value);
         }
         if (value is bool)
         {
             if ((primitiveClrType != typeof(bool)) && ((readerBehavior == null) || (readerBehavior.FormatBehaviorKind != ODataBehaviorKind.WcfDataServicesServer)))
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonReaderUtils_CannotConvertBoolean(primitiveTypeReference.ODataFullName()));
             }
             return(value);
         }
         if (value is DateTime)
         {
             if ((primitiveClrType != typeof(DateTime)) && ((readerBehavior == null) || (readerBehavior.FormatBehaviorKind != ODataBehaviorKind.WcfDataServicesServer)))
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonReaderUtils_CannotConvertDateTime(primitiveTypeReference.ODataFullName()));
             }
             return(value);
         }
         if ((value is DateTimeOffset) && (primitiveClrType != typeof(DateTimeOffset)))
         {
             throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonReaderUtils_CannotConvertDateTimeOffset(primitiveTypeReference.ODataFullName()));
         }
     }
     catch (Exception exception)
     {
         if (!ExceptionUtils.IsCatchableExceptionType(exception))
         {
             throw;
         }
         throw ReaderValidationUtils.GetPrimitiveTypeConversionException(primitiveTypeReference, exception);
     }
     return(value);
 }
        internal static object ConvertValue(
            object value,
            IEdmPrimitiveTypeReference primitiveTypeReference,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool validateNullValue,
            string propertyName)
        {
            Debug.Assert(primitiveTypeReference != null, "primitiveTypeReference != null");

            if (value == null)
            {
                // Only primitive type references are validated. Core model is sufficient.
                ReaderValidationUtils.ValidateNullValue(
                    EdmCoreModel.Instance,
                    primitiveTypeReference,
                    messageReaderSettings,
                    validateNullValue,
                    version,
                    propertyName);
                return(null);
            }

            try
            {
                Type targetType = EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), false);

                string stringValue = value as string;
                if (stringValue != null)
                {
                    return(ConvertStringValue(stringValue, targetType));
                }
                else if (value is Int32)
                {
                    return(ConvertInt32Value((int)value, targetType, primitiveTypeReference));
                }
                else if (value is Decimal)
                {
                    Decimal decimalValue = (Decimal)value;
                    if (targetType == typeof(Int64))
                    {
                        return(Convert.ToInt64(decimalValue));
                    }

                    if (targetType == typeof(Double))
                    {
                        return(Convert.ToDouble(decimalValue));
                    }

                    if (targetType == typeof(Single))
                    {
                        return(Convert.ToSingle(decimalValue));
                    }

                    if (targetType != typeof(Decimal))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDecimal(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is Double)
                {
                    Double doubleValue = (Double)value;
                    if (targetType == typeof(Single))
                    {
                        return(Convert.ToSingle(doubleValue));
                    }

                    if (targetType != typeof(Double))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDouble(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is bool)
                {
                    if (targetType != typeof(bool))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertBoolean(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is DateTime)
                {
                    if (targetType != typeof(DateTime))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDateTime(primitiveTypeReference.ODataFullName()));
                    }
                }
                else if (value is DateTimeOffset)
                {
                    if (targetType != typeof(DateTimeOffset))
                    {
                        throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertDateTimeOffset(primitiveTypeReference.ODataFullName()));
                    }
                }
            }
            catch (Exception e)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(e))
                {
                    throw;
                }

                throw ReaderValidationUtils.GetPrimitiveTypeConversionException(primitiveTypeReference, e, value.ToString());
            }

            // otherwise just return the value without doing any conversion
            return(value);
        }
예제 #26
0
 internal static Type GetPrimitiveClrType(IEdmPrimitiveTypeReference primitiveTypeReference)
 {
     return GetPrimitiveClrType(primitiveTypeReference.PrimitiveDefinition(), primitiveTypeReference.IsNullable);
 }