mirror of
https://github.com/chylex/.NET-Community-Toolkit.git
synced 2025-08-16 23:31:47 +02:00
.github
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
Attributes
Buffers
Enumerables
Extensions
Helpers
Memory
Properties
Streams
Sources
IBufferWriterStream{TWriter}.Memory.cs
IBufferWriterStream{TWriter}.cs
IMemoryOwnerStream{TSource}.cs
MemoryStream.ThrowExceptions.cs
MemoryStream.Validate.cs
MemoryStream.cs
MemoryStream{TSource}.Memory.cs
MemoryStream{TSource}.cs
Box{T}.cs
CommunityToolkit.HighPerformance.csproj
NullableReadOnlyRef{T}.cs
NullableRef{T}.cs
ReadOnlyRef{T}.cs
Ref{T}.cs
CommunityToolkit.Mvvm
CommunityToolkit.Mvvm.SourceGenerators
build
tests
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
.runsettings
CODE_OF_CONDUCT.md
Contributing.md
Directory.Build.props
Directory.Build.targets
License.md
README.md
ThirdPartyNotices.txt
azure-pipelines.yml
dotnet Community Toolkit.sln
toolkit.snk
version.json
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Buffers;
|
|
using System.IO;
|
|
|
|
namespace CommunityToolkit.HighPerformance.Streams;
|
|
|
|
/// <summary>
|
|
/// A <see cref="Stream"/> implementation wrapping an <see cref="IMemoryOwner{T}"/> of <see cref="byte"/> instance.
|
|
/// </summary>
|
|
/// <typeparam name="TSource">The type of source to use for the underlying data.</typeparam>
|
|
internal sealed class IMemoryOwnerStream<TSource> : MemoryStream<TSource>
|
|
where TSource : struct, ISpanOwner
|
|
{
|
|
/// <summary>
|
|
/// The <see cref="IDisposable"/> instance currently in use.
|
|
/// </summary>
|
|
private readonly IDisposable disposable;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="IMemoryOwnerStream{TSource}"/> class.
|
|
/// </summary>
|
|
/// <param name="source">The input <typeparamref name="TSource"/> instance to use.</param>
|
|
/// <param name="disposable">The <see cref="IDisposable"/> instance currently in use.</param>
|
|
public IMemoryOwnerStream(TSource source, IDisposable disposable)
|
|
: base(source, false)
|
|
{
|
|
this.disposable = disposable;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
|
|
this.disposable.Dispose();
|
|
}
|
|
}
|