public OperationImportSegmentTests()
        {
            nullableIntType     = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true);
            nullableDecimalType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), true);
            nullableBinaryType  = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true);
            nullableStringType  = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);

            container = ModelBuildingHelpers.BuildValidEntityContainer();
            model     = new EdmModel();
            model.AddElement(container);

            this.functionIntToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType);
            this.functionIntToInt.AddParameter("Parameter1", this.nullableIntType);
            this.functionImportIntToInt = new EdmFunctionImport(this.container, "Function", this.functionIntToInt);

            this.functionDecimalToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType);
            this.functionDecimalToInt.AddParameter("Parameter1", this.nullableDecimalType);
            this.functionImportDecimalToInt = new EdmFunctionImport(this.container, "Function", this.functionDecimalToInt);

            this.functionBinaryToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType);
            this.functionBinaryToInt.AddParameter("Parameter1", this.nullableBinaryType);
            this.functionImportBinaryToInt = new EdmFunctionImport(this.container, "Function", this.functionBinaryToInt);

            this.functionIntToString = new EdmFunction("Name.Space", "Function", this.nullableStringType);
            this.functionIntToString.AddParameter("Parameter1", this.nullableIntType);
            this.functionImportIntToString = new EdmFunctionImport(this.container, "Function", this.functionIntToString);

            model.AddElement(functionIntToInt);
            model.AddElement(functionDecimalToInt);
            model.AddElement(functionBinaryToInt);
            model.AddElement(functionIntToString);
        }
Ejemplo n.º 2
0
        private void VerifyDateValueReader(string payload, string edmTypeName, object expectedResult)
        {
            IEdmModel model = new EdmModel();
            IEdmPrimitiveTypeReference typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)model.FindType(edmTypeName), true);

            var messageInfo = new ODataMessageInfo
            {
                IsResponse = true,
                MediaType  = JsonLightUtils.JsonLightStreamingMediaType,
                IsAsync    = false,
                Model      = new EdmModel(),
            };

            object actualValue;

            using (var inputContext = new ODataJsonLightInputContext(
                       new StringReader(payload), messageInfo, new ODataMessageReaderSettings()))
            {
                var deserializer = new ODataJsonLightPropertyAndValueDeserializer(inputContext);
                deserializer.JsonReader.Read();
                actualValue = deserializer.ReadNonEntityValue(
                    /*payloadTypeName*/ null,
                    typeReference,
                    /*propertyAndAnnotationCollector*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true,
                    /*isTopLevelPropertyValue*/ true,
                    /*insideResourceValue*/ false,
                    /*propertyName*/ null);
            }
            actualValue.Should().Be(expectedResult, "payload ->{0}<- for type '{1}'", payload, edmTypeName);
        }
Ejemplo n.º 3
0
        private void VerifyDateValueReader(string payload, string edmTypeName, object expectedResult)
        {
            IEdmModel model = new EdmModel();
            IEdmPrimitiveTypeReference typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)model.FindType(edmTypeName), true);

            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(payload));
            object       actualValue;

            using (ODataJsonLightInputContext inputContext = new ODataJsonLightInputContext(
                       ODataFormat.Json,
                       stream,
                       JsonLightUtils.JsonLightStreamingMediaType,
                       Encoding.UTF8,
                       new ODataMessageReaderSettings(),
                       /*readingResponse*/ true,
                       /*synchronous*/ true,
                       model,
                       /*urlResolver*/ null))
            {
                ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(inputContext);
                deserializer.JsonReader.Read();
                actualValue = deserializer.ReadNonEntityValue(
                    /*payloadTypeName*/ null,
                    typeReference,
                    /*duplicatePropertyNamesChecker*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true,
                    /*isTopLevelPropertyValue*/ true,
                    /*insideComplexValue*/ false,
                    /*propertyName*/ null);
            }
            actualValue.Should().Be(expectedResult, "payload ->{0}<- for type '{1}'", payload, edmTypeName);
        }
        private IEdmPrimitiveTypeReference GetFacetlessEdmTypeReference(PrimitiveDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);
            var typeReference = new EdmPrimitiveTypeReference(typeDefinition, dataType.IsNullable);

            return(typeReference);
        }
Ejemplo n.º 5
0
        public void DecimalInExponentialFormJsonLightTest_ExceptionThrownForValueOutOfRange(string untypedValue)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType("Edm.Decimal"), true);

            // Consistent with the behaviour in ASP.NET/ASP.NET Core, exception should be thrown is value is out of range
            Assert.Throws <ODataException>(() => WriteAsUntypedThenReadValue(untypedValue, typeReference, ODataVersion.V4));
        }
Ejemplo n.º 6
0
        public void PrimitiveTypesOfSameKindCanConvertToEachOther()
        {
            var stringType    = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);

            Assert.True(TypePromotionUtils.CanConvertTo(null, stringType, primitiveType));
            Assert.True(TypePromotionUtils.CanConvertTo(null, primitiveType, stringType));
        }
        private void VerifyPrimitiveValuesRoundtripWithTypeInformationIeee754CompatibleFalse(IEnumerable clrValues, string edmTypeName)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType(edmTypeName), true);

            foreach (object clrValue in clrValues)
            {
                this.VerifyPrimitiveValueRoundtrips(clrValue, typeReference, ODataVersion.V4, string.Format("JSON Light roundtrip value {0} with no expected type.", clrValue), isIeee754Compatible: false);
            }
        }
Ejemplo n.º 8
0
        public void DecimalInExponentialFormJsonLightTest(string untypedValue, decimal expectedValue)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType("Edm.Decimal"), true);

            object actualValue = WriteAsUntypedThenReadValue(untypedValue, typeReference, ODataVersion.V4);

            Assert.True(actualValue.GetType().Equals(typeof(decimal)));
            Assert.Equal(expectedValue, actualValue);
        }
        IEdmPrimitiveTypeReference IPrimitiveDataTypeVisitor <IEdmPrimitiveTypeReference> .Visit(StreamDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);

            var typeReference = new EdmPrimitiveTypeReference(
                typeDefinition,
                dataType.IsNullable);

            return(typeReference);
        }
Ejemplo n.º 10
0
        public void Convert_CheckPrimitives(object odataValue, EdmPrimitiveTypeKind edmTypeKind, Type clrType, object expectedResult)
        {
            var edmTypeReference = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(edmTypeKind), false);
            var value            = new ConstantNode(odataValue, odataValue.ToString(), edmTypeReference);
            var result           = ODataModelBinderConverter.Convert(value, edmTypeReference, clrType, "IsActive", null, null);

            Assert.NotNull(result);
            Assert.IsType(clrType, result);
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 11
0
        public void TestComparingEdmTemporalTypeReference()
        {
            var duration = new EdmTemporalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Duration), true);
            var offset   = new EdmTemporalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.DateTimeOffset), true);

            Assert.False(duration.IsEquivalentTo(offset));

            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Duration), true);

            Assert.False(duration.IsEquivalentTo(primitiveType));
        }
Ejemplo n.º 12
0
        public void TestComparingEdmBinaryTypeReference()
        {
            var binaryTypeWithDefaultValue = new EdmBinaryTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true);
            var binaryType = new EdmBinaryTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true, false, null);

            Assert.True(binaryType.IsEquivalentTo(binaryTypeWithDefaultValue));

            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true);

            Assert.False(binaryType.IsEquivalentTo(primitiveType));
        }
Ejemplo n.º 13
0
        public void TestComparingEdmDecimalTypeReference()
        {
            var decimalTypeWithPrecisionNull    = new EdmDecimalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), false, null, null);
            var decimalTypeWithPrecisionNotNull = new EdmDecimalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), false, 1, null);

            Assert.False(decimalTypeWithPrecisionNull.IsEquivalentTo(decimalTypeWithPrecisionNotNull));

            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), true);

            Assert.False(decimalTypeWithPrecisionNull.IsEquivalentTo(primitiveType));
        }
Ejemplo n.º 14
0
        private void VerifyPrimitiveValuesRoundtripWithTypeInformationIeee754CompatibleFalse(IEnumerable clrValues, string edmTypeName)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType(edmTypeName), true);

            foreach (object clrValue in clrValues)
            {
                foreach (ODataVersion version in new ODataVersion[] { ODataVersion.V4, ODataVersion.V401 })
                {
                    this.VerifyPrimitiveValueRoundtrips(clrValue, typeReference, version, isIeee754Compatible: false);
                }
            }
        }
Ejemplo n.º 15
0
        public void TestComparingEdmStringTypeReference()
        {
            var stringType     = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
            var stringTypeCopy = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);

            Assert.True(stringType.IsEquivalentTo(stringTypeCopy));

            var stringTypeWithNullableFalse = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false);
            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);

            Assert.False(stringType.IsEquivalentTo(primitiveType));
            Assert.False(stringType.IsEquivalentTo(stringTypeWithNullableFalse));
        }
Ejemplo n.º 16
0
        public void Constructor_SucceedsForValidPrimitiveType(EdmPrimitiveTypeKind primitiveTypeKind)
        {
            IEdmPrimitiveType edmPrimitiveType = EdmCoreModel.Instance.SchemaElements
                                                 .OfType <IEdmPrimitiveType>()
                                                 .Where(primitiveType => primitiveType.PrimitiveKind == primitiveTypeKind)
                                                 .FirstOrDefault();
            IEdmPrimitiveTypeReference edmPrimitiveTypeReference = new EdmPrimitiveTypeReference(edmPrimitiveType, false);

            var serializer = new ODataPrimitiveSerializer(edmPrimitiveTypeReference);

            Assert.Equal(serializer.EdmType, edmPrimitiveTypeReference);
            Assert.Equal(serializer.ODataPayloadKind, ODataPayloadKind.Property);
        }
        private void VerifyPrimitiveValuesRoundtripWithTypeInformationAndWithExpectedValues(Array clrValues, string edmTypeName, Array expectedValues)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType(edmTypeName), true);

            clrValues.Length.Should().Be(expectedValues.Length);

            for (int iterator = 0; iterator < clrValues.Length; iterator++)
            {
                object clrValue      = clrValues.GetValue(iterator);
                object expectedValue = expectedValues.GetValue(iterator);
                this.VerifyPrimitiveValueRoundtrips(clrValue, typeReference, ODataVersion.V4, string.Format("JSON Light roundtrip value {0} of type {1} of expected value {2}.", clrValue, edmTypeName, expectedValue), isIeee754Compatible: true, expectedValue: expectedValue);
            }
        }
        public void TestCreateODataCollectionWriter_InJsonLight_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataResponseMessage      response = CreateResponse();
            ODataMessageWriterSettings settings = CreateJsonLightSettings();
            IEdmModel         model             = CreateModel();
            IEdmTypeReference itemTypeReference = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageWriter writer = new ODataMessageWriter(response, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => writer.CreateODataCollectionWriter(itemTypeReference));
            }
        }
        public void TestReadProperty_InJsonLight_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage       request              = CreateJsonLightRequest("{\"value\":1}");
            ODataMessageReaderSettings settings             = CreateSettings();
            IEdmModel         model                         = CreateModel();
            IEdmTypeReference expectedPropertyTypeReference = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => reader.ReadProperty(expectedPropertyTypeReference));
            }
        }
Ejemplo n.º 20
0
        public void TestCreateODataCollectionReader_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage       request          = CreateRequest();
            ODataMessageReaderSettings settings         = CreateSettings();
            IEdmModel         model                     = CreateModel();
            IEdmTypeReference expectedItemTypeReference = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                ExceptionAssert.DoesNotThrow(() => reader.CreateODataCollectionReader(expectedItemTypeReference));
            }
        }
        public void TestCreateODataCollectionReader_InJsonLight_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage       request            = CreateJsonLightRequest();
            ODataMessageReaderSettings settings           = CreateSettings();
            IEdmModel           model                     = CreateModel();
            IEdmOperationImport producingOperationImport  = model.EntityContainer.OperationImports().First();
            IEdmTypeReference   expectedItemTypeReference = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => reader.CreateODataCollectionReader(expectedItemTypeReference));
            }
        }
Ejemplo n.º 22
0
        private void VerifyPrimitiveValuesRoundtripWithTypeInformationAndWithExpectedValues(Array clrValues, string edmTypeName, Array expectedValues)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType(edmTypeName), true);

            Assert.Equal(clrValues.Length, expectedValues.Length);

            for (int iterator = 0; iterator < clrValues.Length; iterator++)
            {
                object clrValue      = clrValues.GetValue(iterator);
                object expectedValue = expectedValues.GetValue(iterator);
                foreach (ODataVersion version in new ODataVersion[] { ODataVersion.V4, ODataVersion.V401 })
                {
                    this.VerifyPrimitiveValueRoundtrips(clrValue, typeReference, version, isIeee754Compatible: true, expectedValue: expectedValue);
                }
            }
        }
Ejemplo n.º 23
0
        internal static object ConvertToPayloadValue(object value, ODataSerializerContext writeContext, ODataPayloadValueConverter payloadValueConverter)
        {
            Ensure.NotNull(writeContext, nameof(writeContext));

            IEdmTypeReference edmTypeReference = null;

            if (writeContext.Path != null)
            {
                // Try to get the EDM type of the value from the path.
                var edmType = writeContext.Path.EdmType as IEdmPrimitiveType;
                if (edmType != null)
                {
                    // Just created to call the payload value converter.
                    edmTypeReference = new EdmPrimitiveTypeReference(edmType, true /*isNullable*/);
                }
            }

            return(payloadValueConverter.ConvertToPayloadValue(value, edmTypeReference));
        }
Ejemplo n.º 24
0
        private static bool CheckType(IEdmTypeReference type, IEdmExpression expr, ref ErrorList errors)
        {
            if (type.IsNullable)
            {
                return(true);
            }

            var def = type.Definition;

            switch (def)
            {
            case IEdmPrimitiveType primitive:
                switch (primitive.PrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Boolean:
                    return(Ensure(expr, k => k == EdmExpressionKind.BooleanConstant, "boolean", ref errors));

                case EdmPrimitiveTypeKind.String:
                    return(Ensure(expr, k => k == EdmExpressionKind.StringConstant, "string", ref errors));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Ensure(expr, k => k == EdmExpressionKind.DecimalConstant || k == EdmExpressionKind.IntegerConstant, "number", ref errors));

                default:
                    errors.Add("not implemented: check primitive type {0}", primitive.PrimitiveKind);
                    return(false);
                }

            case IEdmCollectionType collectionType:
                if (expr is IEdmCollectionExpression collection)
                {
                    var elementType = collectionType.ElementType;
                    var valid       = true;
                    foreach (var element in collection.Elements)
                    {
                        valid &= CheckType(elementType, element, ref errors);
                    }
                    return(valid);
                }
                else
                {
                    errors.Add("expected collection");
                    return(false);
                }

            case IEdmStructuredType structuredType:
                if (expr is IEdmRecordExpression record)
                {
                    var pairs = record.Properties.FullOuterJoin(structuredType.Properties(),
                                                                pv => pv.Name,
                                                                pt => pt.Name,
                                                                (name, pv, pt) => (name, pt?.Type, pv?.Value)
                                                                );
                    // errors.Add("matching {0} {1}",
                    //     string.Join(",", record.Properties.Select(p => p.Name)),
                    //     string.Join(",", structuredType.Properties().Select(p => p.Name)));
                    var valid = true;
                    foreach (var match in pairs)
                    {
                        var(name, propType, propValue) = match;
                        if (propType == null)
                        {
                            valid = false;
                            errors.Add("redundant property '{0}' for type {1}", name, structuredType.FullTypeName());
                        }
                        else if (propValue == null)
                        {
                            valid = false;
                            errors.Add("missing property '{0}' for type {1}", name, structuredType.FullTypeName());
                        }
                        else
                        {
                            valid &= CheckType(propType, propValue, ref errors);
                        }
                    }
                    return(valid);
                }
                else
                {
                    errors.Add("expected record, found {0}", expr.ExpressionKind);
                    return(false);
                }

            case IEdmTypeDefinition definition:
                var proxy = new EdmPrimitiveTypeReference(definition.UnderlyingType, type.IsNullable);
                return(CheckType(proxy, expr, ref errors));

            default:
                errors.Add("not implemented: check type {0}", def);
                return(false);
            }
        }
Ejemplo n.º 25
0
        private void VerifyPrimitiveValueRoundtrips(object clrValue, string edmTypeName, ODataVersion version, string description)
        {
            IEdmModel model = new EdmModel();
            IEdmPrimitiveTypeReference typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)model.FindType(edmTypeName), true);

            MemoryStream stream = new MemoryStream();

            using (ODataAtomOutputContext outputContext = new ODataAtomOutputContext(
                       ODataFormat.Atom,
                       new NonDisposingStream(stream),
                       Encoding.UTF8,
                       new ODataMessageWriterSettings()
            {
                Version = version
            },
                       /*writingResponse*/ true,
                       /*synchronous*/ true,
                       model,
                       /*urlResolver*/ null))
            {
                ODataAtomPropertyAndValueSerializer serializer = new ODataAtomPropertyAndValueSerializer(outputContext);
                serializer.XmlWriter.WriteStartElement("ValueElement");
                serializer.WritePrimitiveValue(
                    clrValue,
                    /*collectionValidator*/ null,
                    typeReference,
                    /*serializationTypeNameAnnotation*/ null);
                serializer.XmlWriter.WriteEndElement();
            }

            stream.Position = 0;

            object actualValue;

            using (ODataAtomInputContext inputContext = new ODataAtomInputContext(
                       ODataFormat.Atom,
                       stream,
                       Encoding.UTF8,
                       new ODataMessageReaderSettings(),
                       /*readingResponse*/ true,
                       /*synchronous*/ true,
                       model,
                       /*urlResolver*/ null))
            {
                ODataAtomPropertyAndValueDeserializer deserializer = new ODataAtomPropertyAndValueDeserializer(inputContext);
                deserializer.XmlReader.MoveToContent();
                actualValue = deserializer.ReadNonEntityValue(
                    typeReference,
                    /*duplicatePropertyNamesChecker*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true);
            }

            if (clrValue is byte[])
            {
                ((byte[])actualValue).Should().Equal((byte[])clrValue, description);
            }
            else
            {
                actualValue.Should().Be(clrValue, description);
            }
        }
        internal static object ConvertToPayloadValue(object value, ODataSerializerContext writeContext)
        {
            Ensure.NotNull(writeContext, "writeContext");

            IEdmTypeReference edmTypeReference = null;
            if (writeContext.Path != null)
            {
                // Try to get the EDM type of the value from the path.
                var edmType = writeContext.Path.EdmType as IEdmPrimitiveType;
                if (edmType != null)
                {
                    // Just created to call the payload value converter.
                    edmTypeReference = new EdmPrimitiveTypeReference(edmType, true /*isNullable*/);
                }
            }

            var payloadValueConverter
                = writeContext.Request.GetRequestContainer().GetService<ODataPayloadValueConverter>();
            return payloadValueConverter.ConvertToPayloadValue(value, edmTypeReference);
        }
Ejemplo n.º 27
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()));
        }