Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StyleCleanUp] Resolve CA1507 for exception formatting arguments #10379

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ITextRangeProvider RangeFromChild(IRawElementProviderSimple childElement)
{
if (!(childElement is ElementProxy))
{
throw new ArgumentException(SR.Format(SR.TextProvider_InvalidChild, "childElement"));
throw new ArgumentException(SR.Format(SR.TextProvider_InvalidChild, nameof(childElement)));
}

return (ITextRangeProvider)ElementUtil.Invoke(_peer, new DispatcherOperationCallback(RangeFromChild), childElement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.

Expand Down Expand Up @@ -48,7 +48,7 @@ public bool Compare(ITextRangeProvider range)
{
if (!(range is TextRangeProviderWrapper))
{
throw new ArgumentException(SR.Format(SR.TextRangeProvider_InvalidRangeProvider, "range"));
throw new ArgumentException(SR.Format(SR.TextRangeProvider_InvalidRangeProvider, nameof(range)));
}

return (bool)ElementUtil.Invoke(_peer, new DispatcherOperationCallback(Compare), range);
Expand All @@ -58,7 +58,7 @@ public int CompareEndpoints(TextPatternRangeEndpoint endpoint, ITextRangeProvide
{
if (!(targetRange is TextRangeProviderWrapper))
{
throw new ArgumentException(SR.Format(SR.TextRangeProvider_InvalidRangeProvider, "targetRange"));
throw new ArgumentException(SR.Format(SR.TextRangeProvider_InvalidRangeProvider, nameof(targetRange)));
}

object[] args = new object[] { endpoint, targetRange, targetEndpoint };
Expand Down Expand Up @@ -121,7 +121,7 @@ public void MoveEndpointByRange(TextPatternRangeEndpoint endpoint, ITextRangePro
{
if (!(targetRange is TextRangeProviderWrapper))
{
throw new ArgumentException(SR.Format(SR.TextRangeProvider_InvalidRangeProvider, "targetRange"));
throw new ArgumentException(SR.Format(SR.TextRangeProvider_InvalidRangeProvider, nameof(targetRange)));
}

object[] args = new object[] { endpoint, targetRange, targetEndpoint };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,14 @@ static private void CheckOneDimensionalByteRanges(int[] byteRanges)
// The byteRanges should never be less; perf optimization
if (byteRanges.Length < 2 || (byteRanges.Length % 2) != 0)
{
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, "byteRanges"));
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, nameof(byteRanges)));
}

for (int i = 0; i < byteRanges.Length; i++)
{
if (byteRanges[i] < 0 || byteRanges[i+1] <= 0)
{
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, "byteRanges"));
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, nameof(byteRanges)));
}
i++;
}
Expand All @@ -718,14 +718,14 @@ static private void CheckTwoDimensionalByteRanges(int[,] byteRanges)
{
if (byteRanges.GetLength(0) <= 0 || byteRanges.GetLength(1) != 2)
{
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, "byteRanges"));
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, nameof(byteRanges)));
}

for (int i = 0; i < byteRanges.GetLength(0); ++i)
{
if (byteRanges[i,Offset_Index] < 0 || byteRanges[i,Length_Index] <= 0)
{
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, "byteRanges"));
throw new ArgumentException(SR.Format(SR.InvalidByteRanges, nameof(byteRanges)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public void CopyTo(T[] array, int arrayIndex)
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength,
"arrayIndex",
"array"),
nameof(arrayIndex),
nameof(array)),
nameof(arrayIndex));
}

Expand All @@ -148,8 +148,8 @@ public void CopyTo(T[] array, int arrayIndex)
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength,
"arrayIndex",
"array"));
nameof(arrayIndex),
nameof(array)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public void CopyTo(double[] array, int arrayIndex)
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength,
"arrayIndex",
"array"),
nameof(arrayIndex),
nameof(array)),
nameof(arrayIndex));
}

Expand All @@ -189,8 +189,8 @@ public void CopyTo(double[] array, int arrayIndex)
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength,
"arrayIndex",
"array"));
nameof(arrayIndex),
nameof(array)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public void CopyTo(Point[] array, int arrayIndex)
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength,
"arrayIndex",
"array"),
nameof(arrayIndex),
nameof(array)),
nameof(arrayIndex));
}

Expand All @@ -134,8 +134,8 @@ public void CopyTo(Point[] array, int arrayIndex)
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength,
"arrayIndex",
"array"));
nameof(arrayIndex),
nameof(array)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static bool IsAltKeyRequiredInAccessKeyDefaultScope
{
if (_isSealed)
{
throw new InvalidOperationException(SR.Format(SR.CompatibilityPreferencesSealed, "IsAltKeyRequiredInAccessKeyDefaultScope", "CoreCompatibilityPreferences"));
throw new InvalidOperationException(SR.Format(SR.CompatibilityPreferencesSealed, nameof(IsAltKeyRequiredInAccessKeyDefaultScope), "CoreCompatibilityPreferences"));
}

_isAltKeyRequiredInAccessKeyDefaultScope = value;
Expand Down Expand Up @@ -105,7 +105,7 @@ internal static bool IncludeAllInkInBoundingBox
{
if (_isSealed)
{
throw new InvalidOperationException(SR.Format(SR.CompatibilityPreferencesSealed, "IncludeAllInkInBoundingBox", "CoreCompatibilityPreferences"));
throw new InvalidOperationException(SR.Format(SR.CompatibilityPreferencesSealed, nameof(IncludeAllInkInBoundingBox), "CoreCompatibilityPreferences"));
}

_includeAllInkInBoundingBox = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public DragDropEffects Effects
{
if (!DragDrop.IsValidDragDropEffects(value))
{
throw new ArgumentException(SR.Format(SR.DragDrop_DragDropEffectsInvalid, "value"));
throw new ArgumentException(SR.Format(SR.DragDrop_DragDropEffectsInvalid, nameof(value)));
}

_effects = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public StrokeCollectionChangedEventArgs(StrokeCollection added, StrokeCollection
{
if ( added == null && removed == null )
{
throw new ArgumentException(SR.Format(SR.CannotBothBeNull, "added", "removed"));
throw new ArgumentException(SR.Format(SR.CannotBothBeNull, nameof(added), nameof(removed)));
}
_added = ( added == null ) ? null : new StrokeCollection.ReadOnlyStrokeCollection(added);
_removed = ( removed == null ) ? null : new StrokeCollection.ReadOnlyStrokeCollection(removed);
Expand Down Expand Up @@ -101,7 +101,7 @@ public PropertyDataChangedEventArgs(Guid propertyGuid,
{
if ( newValue == null && previousValue == null )
{
throw new ArgumentException(SR.Format(SR.CannotBothBeNull, "newValue", "previousValue"));
throw new ArgumentException(SR.Format(SR.CannotBothBeNull, nameof(newValue), nameof(previousValue)));
}

_propertyGuid = propertyGuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static string NormalizeKey(string key)

if (key != firstCharacter)
{
throw new ArgumentException(SR.Format(SR.AccessKeyManager_NotAUnicodeCharacter, "key"));
throw new ArgumentException(SR.Format(SR.AccessKeyManager_NotAUnicodeCharacter, nameof(key)));
}

return firstCharacter.ToUpperInvariant();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public InputScopeNameValue NameValue
{
if (!IsValidInputScopeNameValue(value))
{
throw new ArgumentException(SR.Format(SR.InputScope_InvalidInputScopeName, "value"));
throw new ArgumentException(SR.Format(SR.InputScope_InvalidInputScopeName, nameof(value)));
}
_nameValue = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public StylusSystemGestureEventArgs(
{
if (!RawStylusSystemGestureInputReport.IsValidSystemGesture(systemGesture, false, false))
{
throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, "systemGesture"));
throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, nameof(systemGesture)));
}

_id = systemGesture;
Expand Down Expand Up @@ -75,7 +75,7 @@ internal StylusSystemGestureEventArgs(
{
if (!RawStylusSystemGestureInputReport.IsValidSystemGesture(systemGesture, true, false))
{
throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, "systemGesture"));
throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, nameof(systemGesture)));
}

_id = systemGesture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ private static bool UnsafeStartComposition(TextComposition composition)

if (composition._InputManager == null)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, nameof(composition)));
}

if (composition.Stage != TextCompositionStage.None)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasStarted, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasStarted, nameof(composition)));
}

composition.Stage = TextCompositionStage.Started;
Expand All @@ -324,17 +324,17 @@ private static bool UnsafeUpdateComposition(TextComposition composition)

if (composition._InputManager == null)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, nameof(composition)));
}

if (composition.Stage == TextCompositionStage.None)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionNotStarted, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionNotStarted, nameof(composition)));
}

if (composition.Stage == TextCompositionStage.Done)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasDone, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasDone, nameof(composition)));
}

TextCompositionEventArgs textargs = new TextCompositionEventArgs(composition._InputDevice, composition)
Expand All @@ -351,17 +351,17 @@ private static bool UnsafeCompleteComposition(TextComposition composition)

if (composition._InputManager == null)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, nameof(composition)));
}

if (composition.Stage == TextCompositionStage.None)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionNotStarted, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionNotStarted, nameof(composition)));
}

if (composition.Stage == TextCompositionStage.Done)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasDone, "composition"));
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasDone, nameof(composition)));
}

composition.Stage = TextCompositionStage.Done;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public KeySpline(Point controlPoint1, Point controlPoint2)
{
throw new ArgumentException(SR.Format(
SR.Animation_KeySpline_InvalidValue,
"controlPoint1",
nameof(controlPoint1),
controlPoint1));
}

if (!IsValidControlPoint(controlPoint2))
{
throw new ArgumentException(SR.Format(
SR.Animation_KeySpline_InvalidValue,
"controlPoint2",
nameof(controlPoint2),
controlPoint2));
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public Point ControlPoint1
{
throw new ArgumentException(SR.Format(
SR.Animation_KeySpline_InvalidValue,
"ControlPoint1",
nameof(ControlPoint1),
value));
}

Expand Down Expand Up @@ -199,7 +199,7 @@ public Point ControlPoint2
{
throw new ArgumentException(SR.Format(
SR.Animation_KeySpline_InvalidValue,
"ControlPoint2",
nameof(ControlPoint2),
value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void CopyTo(KeyValuePair<int, CharacterMetrics>[] array, int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);

if (index >= array.Length)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, "index", "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, nameof(index), nameof(array)));

CharacterMetrics[][] pageTable = _pageTable;
if (pageTable != null)
Expand All @@ -137,7 +137,7 @@ public void CopyTo(KeyValuePair<int, CharacterMetrics>[] array, int index)
if (metrics != null)
{
if (k >= array.Length)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, nameof(array)));

array[k++] = new KeyValuePair<int, CharacterMetrics>(
(i << PageShift) | j,
Expand Down Expand Up @@ -176,10 +176,10 @@ void SC.ICollection.CopyTo(Array array, int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);

if (index >= array.Length)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, "index", "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, nameof(index), nameof(array)));

if (Count > array.Length - index)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, nameof(array)));

SC.DictionaryEntry[] typedArray = array as SC.DictionaryEntry[];
if (typedArray != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public void CopyTo(KeyValuePair<XmlLanguage, string>[] array, int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);

if (index >= array.Length)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, "index", "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, nameof(index), nameof(array)));

if (_innerDictionary.Count > array.Length - index)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, nameof(array)));

_innerDictionary.CopyTo(array, index);
}
Expand Down Expand Up @@ -145,10 +145,10 @@ void SC.ICollection.CopyTo(Array array, int index)
ArgumentOutOfRangeException.ThrowIfNegative(index);

if (index >= array.Length)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, "index", "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, nameof(index), nameof(array)));

if (_innerDictionary.Count > array.Length - index)
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, "array"));
throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, nameof(array)));

SC.DictionaryEntry[] typedArray = array as SC.DictionaryEntry[];
if (typedArray != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public EllipseGeometry(Rect rect)
{
if (rect.IsEmpty)
{
throw new System.ArgumentException(SR.Format(SR.Rect_Empty, "rect"));
throw new System.ArgumentException(SR.Format(SR.Rect_Empty, nameof(rect)));
}

RadiusX = (rect.Right - rect.X) * (1.0 / 2.0);
Expand Down
Loading