This commit is contained in:
CarloToso
2023-05-25 10:12:42 -07:00
committed by GitHub
parent fa64ecba70
commit 0b42d92d4d
6 changed files with 15 additions and 55 deletions
@@ -276,15 +276,8 @@ namespace Microsoft.Management.UI.Internal
/// <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));
}
@@ -324,15 +317,8 @@ namespace Microsoft.Management.UI.Internal
/// <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;
@@ -50,15 +50,9 @@ namespace Microsoft.PowerShell.Cim
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)
{
@@ -428,10 +428,7 @@ namespace Microsoft.PowerShell.Commands
/// <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();
@@ -532,12 +529,8 @@ namespace Microsoft.PowerShell.Commands
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))
{
@@ -360,15 +360,8 @@ namespace System.Management.Automation
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
@@ -17,10 +17,7 @@ namespace System.Management.Automation.Runspaces
private static Func<string, PSMemberInfoInternalCollection<PSMemberInfo>> GetValueFactoryBasedOnInitCapacity(int capacity)
{
if (capacity <= 0)
{
throw new ArgumentOutOfRangeException(nameof(capacity));
}
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(capacity);
if (capacity > ValueFactoryCacheCount)
{
@@ -28,11 +28,8 @@ namespace System.Management.Automation
{
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)
{