Example #1
0
        private ISpatial ReadSpatialValue(IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue)
        {
            ODataVersionChecker.CheckSpatialValue(base.Version);
            if (this.TryReadNullValue(expectedValueTypeReference, validateNullValue))
            {
                return(null);
            }
            ISpatial spatial = null;

            if (base.JsonReader.NodeType == JsonNodeType.StartObject)
            {
                IDictionary <string, object> source    = this.ReadObjectValue(base.JsonReader);
                GeoJsonObjectFormatter       formatter = SpatialImplementation.CurrentImplementation.CreateGeoJsonObjectFormatter();
                if (expectedValueTypeReference.IsGeographyType())
                {
                    spatial = formatter.Read <Geography>(source);
                }
                else
                {
                    spatial = formatter.Read <Geometry>(source);
                }
            }
            if (spatial == null)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonPropertyAndValueDeserializer_CannotReadSpatialPropertyValue);
            }
            return(spatial);
        }
 private ISpatial ReadSpatialValue(IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue)
 {
     ODataVersionChecker.CheckSpatialValue(base.Version);
     if (this.TryReadNullValue(expectedValueTypeReference, validateNullValue))
     {
         return null;
     }
     ISpatial spatial = null;
     if (base.JsonReader.NodeType == JsonNodeType.StartObject)
     {
         IDictionary<string, object> source = this.ReadObjectValue(base.JsonReader);
         GeoJsonObjectFormatter formatter = SpatialImplementation.CurrentImplementation.CreateGeoJsonObjectFormatter();
         if (expectedValueTypeReference.IsGeographyType())
         {
             spatial = formatter.Read<Geography>(source);
         }
         else
         {
             spatial = formatter.Read<Geometry>(source);
         }
     }
     if (spatial == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonPropertyAndValueDeserializer_CannotReadSpatialPropertyValue);
     }
     return spatial;
 }