当前位置: 首页>>代码示例>>C#>>正文


C# IEdmPrimitiveTypeReference.IsSpatial方法代码示例

本文整理汇总了C#中IEdmPrimitiveTypeReference.IsSpatial方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmPrimitiveTypeReference.IsSpatial方法的具体用法?C# IEdmPrimitiveTypeReference.IsSpatial怎么用?C# IEdmPrimitiveTypeReference.IsSpatial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmPrimitiveTypeReference的用法示例。


在下文中一共展示了IEdmPrimitiveTypeReference.IsSpatial方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadSpatialValue

        /// <summary>
        /// Try and parse spatial type from the json payload.
        /// </summary>
        /// <param name="jsonReader">The JSON reader to read from.</param>
        /// <param name="insideJsonObjectValue">true if the reader is positioned on the first property of the value which is a JSON Object 
        ///     (or the second property if the first one was odata.type).</param>
        /// <param name="inputContext">The input context with all the settings.</param>
        /// <param name="expectedValueTypeReference">Expected edm property type.</param>
        /// <param name="validateNullValue">true to validate null values; otherwise false.</param>
        /// <param name="recursionDepth">The recursion depth to start with.</param>
        /// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
        /// <returns>An instance of the spatial type.</returns>
        internal static ISpatial ReadSpatialValue(
            BufferingJsonReader jsonReader,
            bool insideJsonObjectValue,
            ODataInputContext inputContext,
            IEdmPrimitiveTypeReference expectedValueTypeReference,
            bool validateNullValue,
            int recursionDepth,
            string propertyName)
        {
            Debug.Assert(jsonReader != null, "jsonReader != null");
            Debug.Assert(inputContext != null, "inputContext != null");
            Debug.Assert(expectedValueTypeReference != null, "expectedValueTypeReference != null");
            Debug.Assert(expectedValueTypeReference.IsSpatial(), "TryParseSpatialType must be called only with spatial types");

            // Spatial value can be either null constant or a JSON object
            // If it's a null primitive value, report a null value.
            if (!insideJsonObjectValue && TryReadNullValue(jsonReader, inputContext, expectedValueTypeReference, validateNullValue, propertyName))
            {
                return null;
            }

            Microsoft.Spatial.ISpatial spatialValue = null;
            if (insideJsonObjectValue || jsonReader.NodeType == JsonNodeType.StartObject)
            {
                IDictionary<string, object> jsonObject = ReadObjectValue(jsonReader, insideJsonObjectValue, inputContext, recursionDepth);
                Microsoft.Spatial.GeoJsonObjectFormatter jsonObjectFormatter =
                    Microsoft.Spatial.SpatialImplementation.CurrentImplementation.CreateGeoJsonObjectFormatter();
                if (EdmLibraryExtensions.IsGeographyType(expectedValueTypeReference))
                {
                    spatialValue = jsonObjectFormatter.Read<Microsoft.Spatial.Geography>(jsonObject);
                }
                else
                {
                    spatialValue = jsonObjectFormatter.Read<Microsoft.Spatial.Geometry>(jsonObject);
                }
            }

            if (spatialValue == null)
            {
                throw new ODataException(ODataErrorStrings.ODataJsonReaderCoreUtils_CannotReadSpatialPropertyValue);
            }

            return spatialValue;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:56,代码来源:ODataJsonReaderCoreUtils.cs

示例2: ReadPrimitiveValueImplementation

 private object ReadPrimitiveValueImplementation(IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue)
 {
     if ((expectedValueTypeReference != null) && expectedValueTypeReference.IsSpatial())
     {
         return this.ReadSpatialValue(expectedValueTypeReference, validateNullValue);
     }
     object obj2 = base.JsonReader.ReadPrimitiveValue();
     if ((expectedValueTypeReference != null) && !base.MessageReaderSettings.DisablePrimitiveTypeConversion)
     {
         obj2 = ODataJsonReaderUtils.ConvertValue(obj2, expectedValueTypeReference, base.MessageReaderSettings, base.Version, validateNullValue);
     }
     return obj2;
 }
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:ODataJsonPropertyAndValueDeserializer.cs

示例3: ReadPrimitiveValueImplementation

        /// <summary>
        /// Reads a primitive value.
        /// </summary>
        /// <param name="expectedValueTypeReference">The expected type reference of the value.</param>
        /// <param name="validateNullValue">true to validate null values; otherwise false.</param>
        /// <returns>The value of the primitive value.</returns>
        /// <remarks>
        /// Pre-Condition:  none - Fails if the current node is not a JsonNodeType.PrimitiveValue
        /// Post-Condition: almost anything - the node after the primitive value.
        /// </remarks>
        private object ReadPrimitiveValueImplementation(IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue)
        {
            this.JsonReader.AssertNotBuffering();
            object result;

            if (expectedValueTypeReference != null && expectedValueTypeReference.IsSpatial())
            {
                result = this.ReadSpatialValue(expectedValueTypeReference, validateNullValue);
            }
            else
            {
                result = this.JsonReader.ReadPrimitiveValue();

                if (expectedValueTypeReference != null && !this.MessageReaderSettings.DisablePrimitiveTypeConversion)
                {
                    result = ODataJsonReaderUtils.ConvertValue(result, expectedValueTypeReference, this.MessageReaderSettings, this.Version, validateNullValue);
                }
            }

            this.JsonReader.AssertNotBuffering();

            return result;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:33,代码来源:ODataJsonPropertyAndValueDeserializer.cs

示例4: ReadPrimitiveValue

        /// <summary>
        /// Reads a primitive value.
        /// </summary>
        /// <param name="insideJsonObjectValue">true if the reader is positioned on the first property of the value which is a JSON Object 
        ///     (or the second property if the first one was odata.type).</param>
        /// <param name="expectedValueTypeReference">The expected type reference of the value, or null if none is available.</param>
        /// <param name="validateNullValue">true to validate null values; otherwise false.</param>
        /// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
        /// <returns>The value of the primitive value.</returns>
        /// <remarks>
        /// Pre-Condition:  insideJsonObjectValue == false -> none - Fails if the current node is not a JsonNodeType.PrimitiveValue
        ///                 insideJsonObjectValue == true -> JsonNodeType.Property or JsonNodeType.EndObject - the first property of the value object,
        ///                     or the second property if first was odata.type, or the end-object.
        /// Post-Condition: almost anything - the node after the primitive value.
        /// </remarks>
        private object ReadPrimitiveValue(bool insideJsonObjectValue, IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue, string propertyName)
        {
            object result;

            if (expectedValueTypeReference != null && expectedValueTypeReference.IsSpatial())
            {
                result = ODataJsonReaderCoreUtils.ReadSpatialValue(
                    this.JsonReader,
                    insideJsonObjectValue,
                    this.JsonLightInputContext,
                    expectedValueTypeReference,
                    validateNullValue,
                    this.recursionDepth,
                    propertyName);
            }
            else
            {
                if (insideJsonObjectValue)
                {
                    // We manually throw JSON exception here to get a nicer error message (we expect primitive value and got object).
                    // Otherwise the ReadPrimitiveValue would fail with something like "expected primitive value but found property/end object" which is rather confusing.
                    throw new ODataException(ODataErrorStrings.JsonReaderExtensions_UnexpectedNodeDetectedWithPropertyName(JsonNodeType.PrimitiveValue, JsonNodeType.StartObject, propertyName));
                }

                result = this.JsonReader.ReadPrimitiveValue();

                if (expectedValueTypeReference != null)
                {
                    if ((expectedValueTypeReference.IsDecimal() || expectedValueTypeReference.IsInt64())
                        && result != null)
                    {
                        if ((result is string) ^ this.JsonReader.IsIeee754Compatible)
                        {
                            throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_ConflictBetweenInputFormatAndParameter(expectedValueTypeReference.FullName()));
                        }
                    }

                    result = ODataJsonLightReaderUtils.ConvertValue(
                        result,
                        expectedValueTypeReference,
                        this.MessageReaderSettings,
                        validateNullValue,
                        propertyName,
                        this.Model.GetPayloadValueConverter());
                }
                else
                {
                    if (result is Decimal)
                    {
                        // convert decimal back to double to follow legacy logic when target type is not specified and IEEE754Compatible=false.
                        // we may lose precision for some range of int64 and decimal.
                        return Convert.ToDouble((Decimal)result);
                    }
                }
            }

            return result;
        }
开发者ID:modulexcite,项目名称:odata.net,代码行数:73,代码来源:ODataJsonLightPropertyAndValueDeserializer.cs

示例5: ReadSpatialValue

        /// <summary>
        /// Try and parse spatial type from the json payload.
        /// </summary>
        /// <param name="expectedValueTypeReference">Expected edm property type.</param>
        /// <param name="validateNullValue">true to validate null values; otherwise false.</param>
        /// <returns>An instance of the spatial type.</returns>
        private System.Spatial.ISpatial ReadSpatialValue(IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue)
        {
            Debug.Assert(expectedValueTypeReference != null, "expectedValueTypeReference != null");
            Debug.Assert(expectedValueTypeReference.IsSpatial(), "TryParseSpatialType must be called only with spatial types");

            // Note that we made sure that payload type detection will not return spatial for <V3 payloads
            // So the only way we can get a spatial type reference is if it comes from the model,
            // in which case we want to fail for <V3 payloads, since we can't report spatial values from such payloads.
            ODataVersionChecker.CheckSpatialValue(this.Version);

            // Spatial value can be either null constant or a JSON object
            // If it's a null primitive value, report a null value.
            if (this.TryReadNullValue(expectedValueTypeReference, validateNullValue))
            {
                return null;
            }

            System.Spatial.ISpatial spatialValue = null;
            if (this.JsonReader.NodeType == JsonNodeType.StartObject)
            {
                IDictionary<string, object> jsonObject = this.ReadObjectValue(this.JsonReader);
                System.Spatial.GeoJsonObjectFormatter jsonObjectFormatter = 
                    System.Spatial.SpatialImplementation.CurrentImplementation.CreateGeoJsonObjectFormatter();
                if (EdmLibraryExtensions.IsGeographyType(expectedValueTypeReference))
                {
                    spatialValue = jsonObjectFormatter.Read<System.Spatial.Geography>(jsonObject);
                }
                else
                {
                    spatialValue = jsonObjectFormatter.Read<System.Spatial.Geometry>(jsonObject);
                }
            }

            if (spatialValue == null)
            {
                throw new ODataException(o.Strings.ODataJsonPropertyAndValueDeserializer_CannotReadSpatialPropertyValue);
            }

            return spatialValue;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:46,代码来源:ODataJsonPropertyAndValueDeserializer.cs


注:本文中的IEdmPrimitiveTypeReference.IsSpatial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。