Files
Fishery/Source/FisheryLib/Diagnostics/Internals/Guard.IO.ThrowHelper.cs
T
bbradson 9cdc8ccb4f Fishery
2022-10-24 18:56:18 +02:00

41 lines
1.8 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.Diagnostics.CodeAnalysis;
using System.IO;
namespace FisheryLib.Utility.Diagnostics;
/// <inheritdoc/>
public partial class Guard
{
/// <inheritdoc/>
private partial class ThrowHelper
{
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="CanRead"/> fails.
/// </summary>
[DoesNotReturn]
public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support reading.", name);
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="CanWrite"/> fails.
/// </summary>
[DoesNotReturn]
public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support writing.", name);
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="CanSeek"/> fails.
/// </summary>
[DoesNotReturn]
public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) doesn't support seeking.", name);
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="IsAtStartPosition"/> fails.
/// </summary>
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) => throw new ArgumentException($"Stream {AssertString(name)} ({stream.GetType().ToTypeString()}) must be at position {AssertString(0)}, was at {AssertString(stream.Position)}.", name);
}
}