public void WriteUntypedValue(ODataUntypedValue value) { this.WritePrimitiveVerifier.Should().NotBeNull("WriteUntypedValue was called."); this.WritePrimitiveVerifier(value, null); }
/// <summary> /// Writes an untyped value. /// </summary> /// <param name="value">The untyped value to write.</param> public void WriteUntypedValue( ODataUntypedValue value) { Debug.Assert(value != null, "value != null"); if (string.IsNullOrEmpty(value.RawValue)) { throw new ODataException(ODataErrorStrings.ODataJsonLightValueSerializer_MissingRawValueOnUntyped); } this.JsonWriter.WriteRawValue(value.RawValue); }
private void WriteProperty( ODataProperty property, IEdmStructuredType owningType, bool isTopLevel, bool allowStreamProperty, IDuplicatePropertyNameChecker duplicatePropertyNameChecker) { WriterValidationUtils.ValidatePropertyNotNull(property); string propertyName = property.Name; ODataValue value = property.ODataValue; // If no validation is required, we don't need property serialization info and could try to write null property right away if (!this.MessageWriterSettings.ThrowIfTypeConflictsWithMetadata && this.MessageWriterSettings.IgnoreNullValues) { if (value is ODataNullValue || value == null) { return; } } if (this.JsonLightOutputContext.MessageWriterSettings.Validations != ValidationKinds.None) { WriterValidationUtils.ValidatePropertyName(propertyName); } if (!this.JsonLightOutputContext.PropertyCacheHandler.InResourceSetScope()) { this.currentPropertyInfo = new PropertySerializationInfo(propertyName, owningType) { IsTopLevel = isTopLevel }; } else { this.currentPropertyInfo = this.JsonLightOutputContext.PropertyCacheHandler.GetProperty(propertyName, owningType); } WriterValidationUtils.ValidatePropertyDefined(this.currentPropertyInfo, this.MessageWriterSettings.ThrowOnUndeclaredPropertyForNonOpenType); duplicatePropertyNameChecker.ValidatePropertyUniqueness(property); if (currentPropertyInfo.MetadataType.IsUndeclaredProperty) { WriteODataTypeAnnotation(property, isTopLevel); } WriteInstanceAnnotation(property, isTopLevel, currentPropertyInfo.MetadataType.IsUndeclaredProperty); // handle ODataUntypedValue ODataUntypedValue untypedValue = value as ODataUntypedValue; if (untypedValue != null) { WriteUntypedValue(untypedValue); return; } ODataStreamReferenceValue streamReferenceValue = value as ODataStreamReferenceValue; if (streamReferenceValue != null) { if (!allowStreamProperty) { throw new ODataException(ODataErrorStrings.ODataWriter_StreamPropertiesMustBePropertiesOfODataResource(propertyName)); } Debug.Assert(owningType == null || owningType.IsODataEntityTypeKind(), "The metadata should not allow named stream properties to be defined on a non-entity type."); Debug.Assert(!isTopLevel, "Stream properties are not allowed at the top level."); WriterValidationUtils.ValidateStreamReferenceProperty(property, currentPropertyInfo.MetadataType.EdmProperty, this.WritingResponse); this.WriteStreamReferenceProperty(propertyName, streamReferenceValue); return; } if (value is ODataNullValue || value == null) { this.WriteNullProperty(property); return; } bool isOpenPropertyType = this.IsOpenProperty(property); ODataPrimitiveValue primitiveValue = value as ODataPrimitiveValue; if (primitiveValue != null) { this.WritePrimitiveProperty(primitiveValue, isOpenPropertyType); return; } ODataEnumValue enumValue = value as ODataEnumValue; if (enumValue != null) { this.WriteEnumProperty(enumValue, isOpenPropertyType); return; } ODataCollectionValue collectionValue = value as ODataCollectionValue; if (collectionValue != null) { this.WriteCollectionProperty(collectionValue, isOpenPropertyType); return; } }
/// <summary> /// Writes a untyped property. /// </summary> /// <param name="property">The property to write out.</param> /// <param name="untypedValue">The untyped value to be written</param> /// <param name="isTopLevel">true when writing a top-level property; false for nested properties.</param> private void WriteUntypedProperty( ODataProperty property, ODataUntypedValue untypedValue, bool isTopLevel) { Debug.Assert(untypedValue != null, "untypedValue != null"); this.JsonWriter.WriteName(GetWirePropertyName(isTopLevel, property.Name)); this.JsonLightValueSerializer.WriteUntypedValue(untypedValue); }
private void WriteUntypedValue(ODataUntypedValue untypedValue) { this.JsonWriter.WriteName(this.currentPropertyInfo.WireName); this.jsonLightValueSerializer.WriteUntypedValue(untypedValue); return; }