// 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.IO;
using System.Runtime.CompilerServices;
namespace CommunityToolkit.Diagnostics;
///
partial class Guard
{
///
/// Asserts that the input instance must support reading.
///
/// The input instance to test.
/// The name of the input parameter being tested.
/// Thrown if doesn't support reading.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CanRead(Stream stream, [CallerArgumentExpression("stream")] string name = "")
{
if (stream.CanRead)
{
return;
}
ThrowHelper.ThrowArgumentExceptionForCanRead(stream, name);
}
///
/// Asserts that the input instance must support writing.
///
/// The input instance to test.
/// The name of the input parameter being tested.
/// Thrown if doesn't support writing.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CanWrite(Stream stream, [CallerArgumentExpression("stream")] string name = "")
{
if (stream.CanWrite)
{
return;
}
ThrowHelper.ThrowArgumentExceptionForCanWrite(stream, name);
}
///
/// Asserts that the input instance must support seeking.
///
/// The input instance to test.
/// The name of the input parameter being tested.
/// Thrown if doesn't support seeking.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CanSeek(Stream stream, [CallerArgumentExpression("stream")] string name = "")
{
if (stream.CanSeek)
{
return;
}
ThrowHelper.ThrowArgumentExceptionForCanSeek(stream, name);
}
///
/// Asserts that the input instance must be at the starting position.
///
/// The input instance to test.
/// The name of the input parameter being tested.
/// Thrown if is not at the starting position.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsAtStartPosition(Stream stream, [CallerArgumentExpression("stream")] string name = "")
{
if (stream.Position == 0)
{
return;
}
ThrowHelper.ThrowArgumentExceptionForIsAtStartPosition(stream, name);
}
}