NamespaceSystemLibrary.Common.Framework.Extensions SystemLibrary.Common.Framework.Json.dll
Extensions for streams like reading content as json directly into class through JsonAsync()
StreamExtensions
public static class StreamExtensions
Inheritance
Examples
Arguments
Methods
Reading a Stream async as JsonData converting it into a class T
Used for instance when you read the content of a HttpResponse and directly converting it into T instead of storing as string first
public static Task<T> JsonAsync<T>(this Stream stream, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)
using (var contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
return await contentStream.JsonAsync<T>(jsonSerializerOptions).ConfigureAwait(false);
Generic types
Name | Description |
---|---|
T |
Methods arguments
Type | Name | Description |
---|---|---|
Stream | stream | |
JsonSerializerOptions | options | |
CancellationToken | cancellationToken |
Type | Description |
---|---|
Task<T> | T or default |
Reads a stream and hashing its content as MD5
Remarks
If data is larger than ~200 bytes then .ToSha1Hash() is faster
Reads a stream and hashing its content as MD5
Remarks
If data is larger than ~200 bytes then .ToSha1Hash() is faster
public static Task<string> ToMD5HashAsync(this Stream stream)
Reads a stream and hashing its content as Sha1
Remarks
If data is smaller than ~200 bytes then .ToMD5Hash() is faster
Reads a stream and hashing its content as Sha1
Remarks
If data is smaller than ~200 bytes then .ToMD5Hash() is faster
public static Task<string> ToSha1HashAsync(this Stream stream)
Reads a stream and hashing its content as Sha256
public static Task<string> ToSha256HashAsync(this Stream stream)
}