Use throw helpers in more places, add ObjectDisposedExceptionExtensions
このコミットが含まれているのは:
1 親
19eab4d7af
コミット
c35b2d9394
9ファイル変更
+97
-130
検索条件に一致するファイルはありません
@@ -57,10 +57,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
{
|
||||
T[]? array = this.array;
|
||||
|
||||
if (array is null)
|
||||
{
|
||||
ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
|
||||
}
|
||||
default(ObjectDisposedException).ThrowIfNull(array);
|
||||
|
||||
return array.AsSpan(0, this.index);
|
||||
}
|
||||
@@ -70,28 +67,14 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
/// Advances the current writer.
|
||||
/// </summary>
|
||||
/// <param name="count">The amount to advance.</param>
|
||||
/// <remarks>
|
||||
/// <para>Must be called after <see cref="GetSpan"/>.</para>
|
||||
/// <para>This and the methods below are <see langword="readonly"/> to enable mutating extensions.</para>
|
||||
/// </remarks>
|
||||
/// <remarks>Must be called after <see cref="GetSpan"/>.</remarks>
|
||||
internal void Advance(int count)
|
||||
{
|
||||
T[]? array = this.array;
|
||||
|
||||
if (array is null)
|
||||
{
|
||||
ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
|
||||
}
|
||||
|
||||
if (count < 0)
|
||||
{
|
||||
ArrayPoolBufferWriterHelpers.ThrowArgumentOutOfRangeExceptionForNegativeCount();
|
||||
}
|
||||
|
||||
if (this.index > array.Length - count)
|
||||
{
|
||||
ArrayPoolBufferWriterHelpers.ThrowArgumentExceptionForAdvancedTooFar();
|
||||
}
|
||||
default(ObjectDisposedException).ThrowIfNull(array);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNegative(count);
|
||||
default(ArgumentException).ThrowIf(this.index > array.Length - count);
|
||||
|
||||
this.index += count;
|
||||
}
|
||||
@@ -118,15 +101,8 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
{
|
||||
T[]? array = this.array;
|
||||
|
||||
if (array is null)
|
||||
{
|
||||
ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
|
||||
}
|
||||
|
||||
if (sizeHint < 0)
|
||||
{
|
||||
ArrayPoolBufferWriterHelpers.ThrowArgumentOutOfRangeExceptionForNegativeSizeHint();
|
||||
}
|
||||
default(ObjectDisposedException).ThrowIfNull(array);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNegative(sizeHint);
|
||||
|
||||
if (sizeHint == 0)
|
||||
{
|
||||
@@ -181,46 +157,4 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
|
||||
ArrayPool<T>.Shared.Return(array);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private helpers for <see cref="ArrayPoolBufferWriter{T}"/>.
|
||||
/// </summary>
|
||||
file static class ArrayPoolBufferWriterHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("count", "The count can't be a negative value.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the size hint is negative.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("sizeHint", "The size hint can't be a negative value.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForAdvancedTooFar()
|
||||
{
|
||||
throw new ArgumentException("The buffer writer has advanced too far.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ObjectDisposedException"/> when the array is <see langword="null"/>.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowObjectDisposedException()
|
||||
{
|
||||
throw new ObjectDisposedException("The current buffer has already been disposed.");
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,9 @@ internal abstract class D2D1AffineTransformMapper<T> : D2D1TransformMapper<T, Ma
|
||||
{
|
||||
static void Throw()
|
||||
{
|
||||
throw new ArgumentException("The input transform matrix can't be inverted, so it can't be used for a transform mapper.");
|
||||
// The parameter name is "matrix" and it's passed by users from D2D1TransformMapperFactory<T>.Transform.
|
||||
// Additionally, we explicitly don't use a throw helper here to avoid loading the two string literals.
|
||||
throw new ArgumentException("The input transform matrix can't be inverted, so it can't be used for a transform mapper.", "matrix");
|
||||
}
|
||||
|
||||
Throw();
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする