Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,8 @@ private static void MoveSpanToPosition(ref int currentSpanIndex, ref TextSpan? c
/// <param name="length">Highlight length.</param>
private void AddHighlight(int start, int length)
{
if (start < 0)
{
throw new ArgumentOutOfRangeException("start");
}

if (start + length > this.textBuilder.Length)
{
throw new ArgumentOutOfRangeException("length");
}
ArgumentOutOfRangeException.ThrowIfNegative(start);
ArgumentOutOfRangeException.ThrowIfGreaterThan(this.textBuilder.Length, start + length, nameof(length));

this.highlightedSpans.Add(new TextSpan(start, length));
}
Expand Down Expand Up @@ -324,15 +317,8 @@ internal struct TextSpan
/// <param name="length">Index of the last character in the span.</param>
internal TextSpan(int start, int length)
{
if (start < 0)
{
throw new ArgumentOutOfRangeException("start");
}

if (length < 1)
{
throw new ArgumentOutOfRangeException("length");
}
ArgumentOutOfRangeException.ThrowIfNegative(start);
ArgumentOutOfRangeException.ThrowIfLessThan(1, length);

this.start = start;
this.end = start + length - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,9 @@ internal SensitiveString(int numberOfCharacters)

private unsafe void Copy(char* source, int offset, int charsToCopy)
{
if ((offset < 0) || (offset >= _string.Length))
{
throw new ArgumentOutOfRangeException(nameof(offset));
}

if (offset + charsToCopy > _string.Length)
{
throw new ArgumentOutOfRangeException(nameof(charsToCopy));
}
ArgumentOutOfRangeException.ThrowIfNegative(offset);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(_string.Length, offset);
ArgumentOutOfRangeException.ThrowIfGreaterThan(_string.Length, offset + charsToCopy, nameof(charsToCopy));

fixed (char* target = _string)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,7 @@ private sealed class CircularBuffer<T> : ICollection<T>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="capacity"/> is negative.</exception>
public CircularBuffer(int capacity)
{
if (capacity < 0)
{
throw new ArgumentOutOfRangeException(nameof(capacity));
}
ArgumentOutOfRangeException.ThrowIfNegative(capacity);

_items = new T[capacity];
Clear();
Expand Down Expand Up @@ -532,12 +529,8 @@ public bool Contains(T item)

public void CopyTo(T[] array, int arrayIndex)
{
ArgumentNullException.ThrowIfNull(array);

if (arrayIndex < 0)
{
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
}
ArgumentNullException.ThrowIfNull(array);
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);

if (Count > (array.Length - arrayIndex))
{
Expand Down
11 changes: 2 additions & 9 deletions src/System.Management.Automation/engine/ProgressRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,8 @@ internal static int GetPercentageComplete(DateTime startTime, TimeSpan expectedD
startTime.Kind == DateTimeKind.Utc,
"DateTime arithmetic should always be done in utc mode [to avoid problems when some operands are calculated right before and right after switching to /from a daylight saving time");

if (startTime > now)
{
throw new ArgumentOutOfRangeException(nameof(startTime));
}

if (expectedDuration <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(expectedDuration));
}
ArgumentOutOfRangeException.ThrowIfGreaterThan(now, startTime);
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(TimeSpan.Zero, expectedDuration);

/*
* According to the spec of Checkpoint-Computer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public sealed partial class TypeTable

private static Func<string, PSMemberInfoInternalCollection<PSMemberInfo>> GetValueFactoryBasedOnInitCapacity(int capacity)
{
if (capacity <= 0)
{
throw new ArgumentOutOfRangeException(nameof(capacity));
}
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(capacity);

if (capacity > ValueFactoryCacheCount)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ internal static string Multiply(string s, int times)
{
Diagnostics.Assert(s != null, "caller to verify argument is not null");

if (times < 0)
{
// TODO: this should be a runtime error.
throw new ArgumentOutOfRangeException(nameof(times));
}
// TODO: this should be a runtime error.
ArgumentOutOfRangeException.ThrowIfNegative(times);

if (times == 0 || s.Length == 0)
{
Expand Down