Extension methods converting .NET Stream to Windows Runtime streams and vice versa.
// Source: https://github.com/unoplatform/uno | License: Apache-2.0
// Provided via justclaw.it.com; keep this notice with the code.
#nullable enable
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage.Streams;
namespace System.IO
{
public static partial class WindowsRuntimeStreamExtensions
{
public static IInputStream AsInputStream(this Stream stream)
{
if (!stream.CanRead)
{
throw new NotSupportedException("Cannot convert stream to a IInputStream because stream does not support reading");
}
if (stream is IInputStreamWrapper wrapper
&& wrapper.FindStream() is { } raw)
{
return raw;
}
return new InputStreamOverStream(stream);
}
public static IOutputStream AsOutputStream(this Stream stream)
{
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key