/// <summary>Writes multiple top-level elements, possibly none.</summary> /// <param name="expanded">Expanded properties for the result.</param> /// <param name="elements">Enumerator for elements to write.</param> protected override void WriteTopLevelElements(IExpandedResult expanded, QueryResultInfo elements) { Debug.Assert(elements != null, "elements != null"); Debug.Assert(!this.RequestDescription.IsSingleResult, "!this.RequestDescription.SingleResult"); string title; if (this.RequestDescription.TargetKind != RequestTargetKind.OpenProperty && this.RequestDescription.TargetSource == RequestTargetSource.Property) { title = this.RequestDescription.Property.Name; } else { title = this.RequestDescription.ContainerName; } this.dataServicesODataWriter = this.CreateODataWriter(true /*forFeed*/); bool needPop = this.PushSegmentForRoot(); this.WriteFeedElements( expanded, elements, this.RequestDescription.TargetResourceType.ElementType(), title, // title () => new Uri(this.RequestDescription.LastSegmentInfo.Identifier, UriKind.Relative), () => this.RequestDescription.ResultUri, // absoluteUri true); this.PopSegmentName(needPop); }
/// <summary>Writes a single top-level element.</summary> /// <param name="expanded">Expanded properties for the result.</param> /// <param name="element">Element to write, possibly null.</param> protected override void WriteTopLevelElement(IExpandedResult expanded, object element) { Debug.Assert(this.RequestDescription.IsSingleResult, "this.RequestDescription.SingleResult"); Debug.Assert(this.RequestDescription.TargetKind == RequestTargetKind.Resource, "this.RequestDescription.TargetKind == RequestTargetKind.Resource"); Debug.Assert(element != null, "element != null"); this.dataServicesODataWriter = this.CreateODataWriter(false /*forFeed*/); ResourceType targetResourceType; if (this.RequestDescription.TargetSource == RequestTargetSource.EntitySet || this.RequestDescription.TargetSource == RequestTargetSource.ServiceOperation) { targetResourceType = this.RequestDescription.TargetResourceType; } else { Debug.Assert( this.RequestDescription.TargetSource == RequestTargetSource.Property, "TargetSource(" + this.RequestDescription.TargetSource + ") == Property -- otherwise control shouldn't be here."); Debug.Assert(this.RequestDescription.Property != null, "this.RequestDescription.Property - otherwise Property source set with no Property specified."); Debug.Assert( this.RequestDescription.Property.TypeKind == ResourceTypeKind.EntityType, "SyndicationSerializer.WriteTopLevelElement should only be called for serializing out entity types"); targetResourceType = this.RequestDescription.Property.ResourceType; } bool needPop = this.PushSegmentForRoot(); this.WriteEntry( expanded, // expanded element, // element false, // resourceInstanceInFeed targetResourceType); // expectedType this.PopSegmentName(needPop); }
/// <summary>Writes multiple top-level elements, possibly none.</summary> /// <param name="expanded">Expanded properties for the result.</param> /// <param name="elements">Enumerator for elements to write.</param> protected override void WriteTopLevelElements(IExpandedResult expanded, QueryResultInfo elements) { Debug.Assert(elements != null, "elements != null"); Debug.Assert(!this.RequestDescription.IsSingleResult, "!this.RequestDescription.SingleResult"); string title; if (this.RequestDescription.TargetKind != RequestTargetKind.OpenProperty && this.RequestDescription.TargetSource == RequestTargetSource.Property) { title = this.RequestDescription.Property.Name; } else { title = this.RequestDescription.ContainerName; } this.dataServicesODataWriter = this.CreateODataWriter(true /*forFeed*/); bool needPop = this.PushSegmentForRoot(); this.WriteFeedElements( expanded, elements, this.RequestDescription.TargetResourceType.ElementType(), title, // title () => new Uri(this.RequestDescription.LastSegmentInfo.Identifier, UriKind.Relative), () => this.RequestDescription.ResultUri, // absoluteUri true); this.PopSegmentName(needPop); }
/// <summary>Writes a single top-level element.</summary> /// <param name="expanded">Expanded properties for the result.</param> /// <param name="element">Element to write, possibly null.</param> protected override void WriteTopLevelElement(IExpandedResult expanded, object element) { Debug.Assert(this.RequestDescription.IsSingleResult, "this.RequestDescription.SingleResult"); Debug.Assert(this.RequestDescription.TargetKind == RequestTargetKind.Resource, "this.RequestDescription.TargetKind == RequestTargetKind.Resource"); Debug.Assert(element != null, "element != null"); this.dataServicesODataWriter = this.CreateODataWriter(false /*forFeed*/); ResourceType targetResourceType; if (this.RequestDescription.TargetSource == RequestTargetSource.EntitySet || this.RequestDescription.TargetSource == RequestTargetSource.ServiceOperation) { targetResourceType = this.RequestDescription.TargetResourceType; } else { Debug.Assert( this.RequestDescription.TargetSource == RequestTargetSource.Property, "TargetSource(" + this.RequestDescription.TargetSource + ") == Property -- otherwise control shouldn't be here."); Debug.Assert(this.RequestDescription.Property != null, "this.RequestDescription.Property - otherwise Property source set with no Property specified."); Debug.Assert( this.RequestDescription.Property.TypeKind == ResourceTypeKind.EntityType, "SyndicationSerializer.WriteTopLevelElement should only be called for serializing out entity types"); targetResourceType = this.RequestDescription.Property.ResourceType; } bool needPop = this.PushSegmentForRoot(); this.WriteEntry( expanded, // expanded element, // element false, // resourceInstanceInFeed targetResourceType); // expectedType this.PopSegmentName(needPop); }