本文整理汇总了C#中ODataMessageReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ODataMessageReader.Dispose方法的具体用法?C# ODataMessageReader.Dispose怎么用?C# ODataMessageReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataMessageReader
的用法示例。
在下文中一共展示了ODataMessageReader.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromStreamAsync
/// <inheritdoc/>
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
if (type == null)
{
throw Error.ArgumentNull("type");
}
if (readStream == null)
{
throw Error.ArgumentNull("readStream");
}
if (_request == null)
{
throw Error.InvalidOperation(SRResources.ReadFromStreamAsyncMustHaveRequest);
}
return TaskHelpers.RunSynchronously<object>(() =>
{
object result;
HttpContentHeaders contentHeaders = content == null ? null : content.Headers;
// If content length is 0 then return default value for this type
if (contentHeaders == null || contentHeaders.ContentLength == 0)
{
result = GetDefaultValueForType(type);
}
else
{
IEdmModel model = _request.GetEdmModel();
if (model == null)
{
throw Error.InvalidOperation(SRResources.RequestMustHaveModel);
}
Type originalType = type;
bool isPatchMode = TryGetInnerTypeForDelta(ref type);
ODataDeserializer deserializer = _deserializerProvider.GetODataDeserializer(model, type);
if (deserializer == null)
{
throw Error.Argument("type", SRResources.FormatterReadIsNotSupportedForType, type.FullName, GetType().FullName);
}
ODataMessageReader oDataMessageReader = null;
ODataMessageReaderSettings oDataReaderSettings = new ODataMessageReaderSettings { DisableMessageStreamDisposal = true, MessageQuotas = MessageReaderQuotas };
try
{
IODataRequestMessage oDataRequestMessage = new ODataMessageWrapper(readStream, contentHeaders);
oDataMessageReader = new ODataMessageReader(oDataRequestMessage, oDataReaderSettings, model);
ODataPath path = _request == null ? null : _request.GetODataPath();
ODataDeserializerContext readContext = new ODataDeserializerContext
{
IsPatchMode = isPatchMode,
Path = path,
Model = model
};
if (isPatchMode)
{
readContext.PatchEntityType = originalType;
}
result = deserializer.Read(oDataMessageReader, readContext);
}
catch (Exception e)
{
if (formatterLogger == null)
{
throw;
}
formatterLogger.LogError(String.Empty, e);
result = GetDefaultValueForType(type);
}
finally
{
if (oDataMessageReader != null)
{
oDataMessageReader.Dispose();
}
}
}
return result;
});
}
示例2: ReadFromStreamAsync
/// <inheritdoc/>
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
if (type == null)
{
throw Error.ArgumentNull("type");
}
if (readStream == null)
{
throw Error.ArgumentNull("readStream");
}
object result = null;
HttpContentHeaders contentHeaders = content == null ? null : content.Headers;
// If content length is 0 then return default value for this type
if (contentHeaders != null && contentHeaders.ContentLength == 0)
{
result = GetDefaultValueForType(type);
}
else
{
bool isPatchMode = TryGetInnerTypeForDelta(ref type);
ODataDeserializer deserializer = ODataDeserializerProvider.GetODataDeserializer(type);
if (deserializer == null)
{
throw Error.Argument("type", SRResources.FormatterReadIsNotSupportedForType, type.FullName, GetType().FullName);
}
ODataMessageReader oDataMessageReader = null;
ODataMessageReaderSettings oDataReaderSettings = new ODataMessageReaderSettings { DisableMessageStreamDisposal = true };
try
{
IODataRequestMessage oDataRequestMessage = new ODataMessageWrapper(readStream, contentHeaders);
oDataMessageReader = new ODataMessageReader(oDataRequestMessage, oDataReaderSettings, ODataDeserializerProvider.EdmModel);
ODataDeserializerContext readContext = new ODataDeserializerContext { IsPatchMode = isPatchMode, PatchKeyMode = PatchKeyMode };
result = deserializer.Read(oDataMessageReader, readContext);
}
finally
{
if (oDataMessageReader != null)
{
oDataMessageReader.Dispose();
}
}
}
return TaskHelpers.FromResult(result);
}