Skip to content

Instantly share code, notes, and snippets.

@ODataTeam
Last active August 29, 2015 14:12
Show Gist options
  • Save ODataTeam/4d6b8b682c1f392bda5f to your computer and use it in GitHub Desktop.
Save ODataTeam/4d6b8b682c1f392bda5f to your computer and use it in GitHub Desktop.
internal sealed class CsvOutputContext : ODataOutputContext
{
private Stream stream;
public CsvOutputContext(
ODataFormat format,
ODataMessageWriterSettings settings,
ODataMessageInfo messageInfo,
bool synchronous)
: base(format, settings, messageInfo.IsResponse, synchronous, messageInfo.Model, messageInfo.UrlResolver)
{
this.stream = messageInfo.GetMessageStream();
this.Writer = new StreamWriter(this.stream);
}
public TextWriter Writer { get; private set; }
public override ODataWriter CreateODataEntryWriter(IEdmNavigationSource navigationSource, IEdmEntityType entityType)
{
return new CsvWriter(this, entityType);
}
public override ODataWriter CreateODataFeedWriter(IEdmEntitySetBase entitySet, IEdmEntityType entityType)
{
return new CsvWriter(this, entityType);
}
public void Flush()
{
this.stream.Flush();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
try
{
if (this.Writer != null)
{
this.Writer.Dispose();
}
if (this.stream != null)
{
this.stream.Dispose();
}
}
finally
{
this.Writer = null;
this.stream = null;
}
}
base.Dispose(disposing);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment