Ejemplo n.º 1
0
        /// <summary>
        /// Writes the given deltaLink specified by the parameter graph as a part of an existing OData message using the given
        /// messageWriter and the writeContext.
        /// </summary>
        /// <param name="value">The object to be written.</param>
        /// <param name="writer">The <see cref="ODataDeltaWriter" /> to be used for writing.</param>
        /// <param name="writeContext">The <see cref="ODataSerializerContext"/>.</param>
        public virtual async Task WriteDeltaLinkAsync(object value, ODataWriter writer, ODataSerializerContext writeContext)
        {
            if (value == null)
            {
                throw Error.ArgumentNull(nameof(value));
            }

            if (writer == null)
            {
                throw Error.ArgumentNull(nameof(writer));
            }

            ODataDeltaLink odataDeltaLink;

            if (value is EdmDeltaLink edmDeltaLink) // typeless
            {
                odataDeltaLink = new ODataDeltaLink(edmDeltaLink.Source, edmDeltaLink.Target, edmDeltaLink.Relationship);
            }
            else if (value is IDeltaLink deltaLink) // typed
            {
                odataDeltaLink = new ODataDeltaLink(deltaLink.Source, deltaLink.Target, deltaLink.Relationship);
            }
            else
            {
                throw new SerializationException(Error.Format(SRResources.CannotWriteType, GetType().Name, value.GetType().FullName));
            }

            if (odataDeltaLink != null)
            {
                await writer.WriteDeltaLinkAsync(odataDeltaLink).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Writes the given deltaLink specified by the parameter graph as a part of an existing OData message using the given
        /// messageWriter and the writeContext.
        /// </summary>
        /// <param name="graph">The object to be written.</param>
        /// <param name="writer">The <see cref="ODataDeltaWriter" /> to be used for writing.</param>
        /// <param name="writeContext">The <see cref="ODataSerializerContext"/>.</param>
        public virtual async Task WriteDeltaLinkAsync(object graph, ODataWriter writer, ODataSerializerContext writeContext)
        {
            if (graph == null)
            {
                throw Error.ArgumentNull(nameof(graph));
            }

            if (writer == null)
            {
                throw Error.ArgumentNull(nameof(writer));
            }

            EdmDeltaLink edmDeltaLink = graph as EdmDeltaLink;

            if (edmDeltaLink == null)
            {
                throw new SerializationException(
                          Error.Format(SRResources.CannotWriteType, GetType().Name, graph.GetType().FullName));
            }

            ODataDeltaLink deltaLink = new ODataDeltaLink(
                edmDeltaLink.Source,
                edmDeltaLink.Target,
                edmDeltaLink.Relationship);

            if (deltaLink != null)
            {
                await writer.WriteDeltaLinkAsync(deltaLink).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the given deltaLink specified by the parameter graph as a part of an existing OData message using the given
        /// messageWriter and the writeContext.
        /// </summary>
        /// <param name="graph">The object to be written.</param>
        /// <param name="writer">The <see cref="ODataDeltaWriter" /> to be used for writing.</param>
        /// <param name="writeContext">The <see cref="ODataSerializerContext"/>.</param>
        public async Task WriteDeltaLinkAsync(object graph, ODataWriter writer, ODataSerializerContext writeContext)
        {
            ODataDeltaLink deltaLink = GetDeltaLink(graph);

            if (deltaLink != null)
            {
                await writer.WriteDeltaLinkAsync(deltaLink);
            }
        }