private ODataCollectionWriter CreateCollectionWriterImplementation(string parameterName, IEdmTypeReference expectedItemType) { ODataCollectionWriter writer = this.CreateFormatCollectionWriter(parameterName, expectedItemType); this.ReplaceScope(ParameterWriterState.ActiveSubWriter); return(writer); }
/// <summary> /// Creates an <see cref="ODataCollectionWriter"/> to write the value of a collection parameter. /// </summary> /// <param name="parameterName">The name of the collection parameter to write.</param> /// <param name="expectedItemType">The type reference of the expected item type or null if no expected item type exists.</param> /// <returns>The newly created <see cref="ODataCollectionWriter"/>.</returns> private ODataCollectionWriter CreateCollectionWriterImplementation(string parameterName, IEdmTypeReference expectedItemType) { Debug.Assert(this.State == ParameterWriterState.CanWriteParameter, "this.State == ParameterWriterState.CanWriteParameter"); ODataCollectionWriter collectionWriter = this.CreateFormatCollectionWriter(parameterName, expectedItemType); this.ReplaceScope(ParameterWriterState.ActiveSubWriter); return(collectionWriter); }
/// <summary> /// Writes the given <paramref name="graph"/> using the given <paramref name="writer"/>. /// </summary> /// <param name="writer">The <see cref="ODataCollectionWriter"/> to use.</param> /// <param name="graph">The collection to write.</param> /// <param name="writeContext">The serializer context.</param> public void WriteCollection(ODataCollectionWriter writer, object graph, ODataSerializerContext writeContext) { if (writer == null) { throw Error.ArgumentNull("writer"); } ODataCollectionValue collectionValue = CreateODataValue(graph, writeContext) as ODataCollectionValue; writer.WriteStart(new ODataCollectionStart { Name = writeContext.RootElementName }); if (collectionValue != null) { foreach (object item in collectionValue.Items) { writer.WriteItem(item); } } writer.WriteEnd(); }
protected override void WriteTopLevelElements(IExpandedResult expanded, IEnumerator elements, bool hasMoved) { if (base.RequestDescription.LinkUri) { bool needPop = base.PushSegmentForRoot(); this.WriteLinkCollection(elements, hasMoved); base.PopSegmentName(needPop); } else { this.collectionWriter = this.writer.CreateODataCollectionWriter(); ODataCollectionStart collectionStart = new ODataCollectionStart { Name = this.ComputeContainerName() }; this.collectionWriter.WriteStart(collectionStart); while (hasMoved) { object current = elements.Current; ResourceType propertyResourceType = (current == null) ? base.RequestDescription.TargetResourceType : WebUtil.GetResourceType(base.Provider, current); if (propertyResourceType == null) { throw new InvalidOperationException(System.Data.Services.Strings.Serializer_UnsupportedTopLevelType(current.GetType())); } this.collectionWriter.WriteItem(base.GetPropertyValue("element", propertyResourceType, current, false)); hasMoved = elements.MoveNext(); } this.collectionWriter.WriteEnd(); this.collectionWriter.Flush(); } }