/// <summary>
        /// Write an <see cref="ODataProperty" /> to the given stream. This method creates an
        /// async buffered stream and writes the property to it.
        /// </summary>
        /// <param name="property">The property to write.</param>
        internal void WriteTopLevelProperty(ODataProperty property)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(property != null, "property != null");
            Debug.Assert(!(property.Value is ODataStreamReferenceValue), "!(property.Value is ODataStreamReferenceValue)");

            this.WriteTopLevelPayload(
                () =>
            {
                this.JsonWriter.StartObjectScope();

                Uri metadataUri;
                ODataJsonLightMetadataUriBuilder metadataUriBuilder = this.JsonLightOutputContext.CreateMetadataUriBuilder();
                if (metadataUriBuilder.TryBuildMetadataUriForValue(property, out metadataUri))
                {
                    this.WriteMetadataUriProperty(metadataUri);
                }

                // Note we do not allow named stream properties to be written as top level property.
                this.JsonLightValueSerializer.AssertRecursionDepthIsZero();
                this.WriteProperty(
                    property,
                    null /*owningType*/,
                    true /* isTopLevel */,
                    false /* allowStreamProperty */,
                    this.CreateDuplicatePropertyNamesChecker(),
                    null /* projectedProperties */);
                this.JsonLightValueSerializer.AssertRecursionDepthIsZero();

                this.JsonWriter.EndObjectScope();
            });
        }
Exemple #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="jsonLightOutputContext">The output context to write to.</param>
        internal ODataJsonLightEntityReferenceLinkSerializer(ODataJsonLightOutputContext jsonLightOutputContext)
            : base(jsonLightOutputContext)
        {
            DebugUtils.CheckNoExternalCallers();

            // DEVNOTE: grab this early so that any validation errors are thrown at creation time rather than when Write___ is called.
            this.metadataUriBuilder = jsonLightOutputContext.CreateMetadataUriBuilder();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="jsonLightOutputContext">The output context to write to.</param>
        /// <param name="writingTopLevelCollection">true when writing a top-level collection that requires the 'value' wrapper object; otherwise false.</param>
        internal ODataJsonLightCollectionSerializer(ODataJsonLightOutputContext jsonLightOutputContext, bool writingTopLevelCollection)
            : base(jsonLightOutputContext)
        {
            DebugUtils.CheckNoExternalCallers();
            this.writingTopLevelCollection = writingTopLevelCollection;

            // DEVNOTE: grab this early so that any validation errors are thrown at creation time rather than when Write___ is called.
            this.metadataUriBuilder = jsonLightOutputContext.CreateMetadataUriBuilder();
        }
Exemple #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="jsonLightOutputContext">The output context to write to.</param>
        internal ODataJsonLightEntryAndFeedSerializer(ODataJsonLightOutputContext jsonLightOutputContext)
            : base(jsonLightOutputContext)
        {
            DebugUtils.CheckNoExternalCallers();
            this.annotationGroups = new Dictionary <string, ODataJsonLightAnnotationGroup>(StringComparer.Ordinal);

            // DEVNOTE: grab this early so that any validation errors are thrown at creation time rather than when Write___ is called.
            this.metadataUriBuilder = jsonLightOutputContext.CreateMetadataUriBuilder();
        }
 /// <summary>
 /// Creates a metadata uri builder for the current output context.
 /// </summary>
 /// <returns>The metadata uri builder to use when writing.</returns>
 internal ODataJsonLightMetadataUriBuilder CreateMetadataUriBuilder()
 {
     DebugUtils.CheckNoExternalCallers();
     return(ODataJsonLightMetadataUriBuilder.CreateFromSettings(this.MetadataLevel, this.WritingResponse, this.MessageWriterSettings, this.Model));
 }