/// <summary> /// Writes the odata.type property annotation for the specified property with the specified type name. /// </summary> /// <param name="propertyName">The name of the property for which to write the odata.type annotation.</param> /// <param name="typeName">The type name to write.</param> public void WriteODataTypePropertyAnnotation(string propertyName, string typeName) { Debug.Assert(!string.IsNullOrEmpty(propertyName), "!string.IsNullOrEmpty(propertyName)"); Debug.Assert(typeName != null, "typeName != null"); // "<propertyName>@odata.type": #"typename" WritePropertyAnnotationName(propertyName, ODataAnnotationNames.ODataType); jsonWriter.WriteValue(WriterUtils.PrefixTypeNameForWriting(typeName, odataVersion)); }
public void TypeNameShouldBeWrittenIfSpatialValueIsMoreDerivedThanMetadataType_401() { var typeFromMetadata = EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, true); var typeFromValue = EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, false); var result = this.typeNameOracle.GetValueTypeNameForWriting(new ODataPrimitiveValue(Microsoft.Spatial.GeographyPoint.Create(42, 42)), typeFromMetadata, typeFromValue, /* isOpenProperty*/ false); Assert.Equal("Edm.GeographyPoint", result); Assert.Equal("GeographyPoint", WriterUtils.PrefixTypeNameForWriting(result, ODataVersion.V401)); }
/// <summary> /// Asynchronously writes the odata.type property annotation for the specified property with the specified type name. /// </summary> /// <param name="propertyName">The name of the property for which to write the odata.type annotation.</param> /// <param name="typeName">The type name to write.</param> /// <returns>A task that represents the asynchronous write operation.</returns> public async Task WriteODataTypePropertyAnnotationAsync(string propertyName, string typeName) { this.AssertAsynchronous(); Debug.Assert(!string.IsNullOrEmpty(propertyName), "!string.IsNullOrEmpty(propertyName)"); Debug.Assert(typeName != null, "typeName != null"); // "<propertyName>@odata.type": #"typename" await WritePropertyAnnotationNameAsync(propertyName, ODataAnnotationNames.ODataType) .ConfigureAwait(false); await asyncJsonWriter.WriteValueAsync(WriterUtils.PrefixTypeNameForWriting(typeName, odataVersion)) .ConfigureAwait(false); }
public void TypeNameShouldBeWrittenForUndeclaredCollectionProperty() { var typeFromValue = EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(false)); var result = this.typeNameOracle.GetValueTypeNameForWriting(new ODataCollectionValue() { TypeName = "Collection(String)" }, null, typeFromValue, /* isOpenProperty*/ true); Assert.Equal("Collection(Edm.String)", result); Assert.Equal("#Collection(String)", WriterUtils.PrefixTypeNameForWriting(result, ODataVersion.V4)); }
/// <summary> /// Writes the odata.type instance annotation with the specified type name. /// </summary> /// <param name="typeName">The type name to write.</param> /// <param name="writeRawValue">Whether to write the raw typeName without removing/adding prefix 'Edm.'/'#'.</param> public void WriteODataTypeInstanceAnnotation(string typeName, bool writeRawValue = false) { Debug.Assert(typeName != null, "typeName != null"); // "@odata.type": "#typename" WriteInstanceAnnotationName(ODataAnnotationNames.ODataType); if (writeRawValue) { jsonWriter.WriteValue(typeName); } else { jsonWriter.WriteValue(WriterUtils.PrefixTypeNameForWriting(typeName, odataVersion)); } }
/// <summary> /// Asynchronously writes the odata.type instance annotation with the specified type name. /// </summary> /// <param name="typeName">The type name to write.</param> /// <param name="writeRawValue">Whether to write the raw typeName without removing/adding prefix 'Edm.'/'#'.</param> /// <returns>A task that represents the asynchronous write operation.</returns> public async Task WriteODataTypeInstanceAnnotationAsync(string typeName, bool writeRawValue = false) { this.AssertAsynchronous(); Debug.Assert(typeName != null, "typeName != null"); // "@odata.type": "#typename" await WriteInstanceAnnotationNameAsync(ODataAnnotationNames.ODataType) .ConfigureAwait(false); if (writeRawValue) { await asyncJsonWriter.WriteValueAsync(typeName).ConfigureAwait(false); } else { await asyncJsonWriter.WriteValueAsync(WriterUtils.PrefixTypeNameForWriting(typeName, odataVersion)) .ConfigureAwait(false); } }