Skip to content

[StyleCleanUp] Addressing CA warnings Part 2 #10186

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

Merged
merged 2 commits into from
Jan 30, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ dotnet_diagnostic.CA1310.severity = suggestion
# CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'
dotnet_diagnostic.CA1419.severity = suggestion

# CA1507: Use nameof in place of string
dotnet_diagnostic.CA1507.severity = suggestion

# CA1510: Use ArgumentNullException throw helper
dotnet_diagnostic.CA1510.severity = suggestion

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 @@ -108,7 +108,7 @@ private static AutomationEvent GetRegisteredEventObjectHelper(AutomationEvents e
case AutomationEvents.ActiveTextPositionChanged: eventObject = AutomationElementIdentifiers.ActiveTextPositionChangedEvent; break;

default:
throw new ArgumentException(SR.Automation_InvalidEventId, "eventId");
throw new ArgumentException(SR.Automation_InvalidEventId, nameof(eventId));
}

if ((eventObject != null) && (!_eventsTable.ContainsKey(eventObject.Id)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ internal static void SplitFontFaceIndex(Uri fontUri, out Uri fontSourceUri, out
out faceIndex
))
{
throw new ArgumentException(SR.FaceIndexMustBePositiveOrZero, "fontUri");
throw new ArgumentException(SR.FaceIndexMustBePositiveOrZero, nameof(fontUri));
}

// face index was specified in a fragment, we need to strip off fragment from the source Uri
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 @@ -305,7 +305,7 @@ internal double Baseline
get { return _baseline; }
set
{
CompositeFontParser.VerifyNonNegativeMultiplierOfEm("Baseline", ref value);
CompositeFontParser.VerifyNonNegativeMultiplierOfEm(nameof(Baseline), ref value);
_baseline = value;
}
}
Expand All @@ -319,7 +319,7 @@ internal double LineSpacing
get { return _lineSpacing; }
set
{
CompositeFontParser.VerifyPositiveMultiplierOfEm("LineSpacing", ref value);
CompositeFontParser.VerifyPositiveMultiplierOfEm(nameof(LineSpacing), ref value);
_lineSpacing = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ internal void SetFace(int faceIndex)
else
{
if (faceIndex != 0)
throw new ArgumentOutOfRangeException("faceIndex", SR.FaceIndexValidOnlyForTTC);
throw new ArgumentOutOfRangeException(nameof(faceIndex), SR.FaceIndexValidOnlyForTTC);
}

try
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 @@ -53,7 +53,7 @@ public override object ConvertFrom(ITypeDescriptorContext td, CultureInfo ci, ob

if (null == s)
{
throw new ArgumentException(SR.Format(SR.General_BadType, "ConvertFrom"), "value");
throw new ArgumentException(SR.Format(SR.General_BadType, "ConvertFrom"), nameof(value));
}

return ConvertFromCore(td, ci, s);
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 @@ -55,7 +55,7 @@ internal ByteRangeDownloader(Uri requestedUri, string tempFileName, SafeWaitHand

if (tempFileName.Length <= 0)
{
throw new ArgumentException(SR.InvalidTempFileName, "tempFileName");
throw new ArgumentException(SR.InvalidTempFileName, nameof(tempFileName));
}

_tempFileStream = File.Open(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
Expand Down Expand Up @@ -402,14 +402,14 @@ private ByteRangeDownloader(Uri requestedUri, SafeWaitHandle eventHandle)
// Ensure uri is correct scheme (http or https) Do case-sensitive comparison since Uri.Scheme contract is to return in lower case only.
if (!string.Equals(requestedUri.Scheme, Uri.UriSchemeHttp, StringComparison.Ordinal) && !string.Equals(requestedUri.Scheme, Uri.UriSchemeHttps, StringComparison.Ordinal))
{
throw new ArgumentException(SR.InvalidScheme, "requestedUri");
throw new ArgumentException(SR.InvalidScheme, nameof(requestedUri));
}

ArgumentNullException.ThrowIfNull(eventHandle);

if (eventHandle.IsInvalid || eventHandle.IsClosed)
{
throw new ArgumentException(SR.InvalidEventHandle, "eventHandle");
throw new ArgumentException(SR.InvalidEventHandle, nameof(eventHandle));
}

_requestedUri = requestedUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override int Read(byte[] buffer, int offset, int count)
checked
{
if (offset + count > buffer.Length)
throw new ArgumentException(SR.IOBufferOverflow, "buffer");
throw new ArgumentException(SR.IOBufferOverflow, nameof(buffer));

// make sure some data is in the stream - block until it is
int bytesAvailable = GetData(new Block(_position, count));
Expand Down Expand Up @@ -248,7 +248,7 @@ public override long Seek(long offset, SeekOrigin origin)

default:
{
throw new ArgumentOutOfRangeException("origin", SR.SeekOriginInvalid);
throw new ArgumentOutOfRangeException(nameof(origin), SR.SeekOriginInvalid);
}
}
}
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 @@ -155,7 +155,7 @@ private static void ValidateUriKey(Uri uri)

if (!uri.IsAbsoluteUri)
{
throw new ArgumentException(SR.UriMustBeAbsolute, "uri");
throw new ArgumentException(SR.UriMustBeAbsolute, nameof(uri));
}
}

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 @@ -148,7 +148,7 @@ internal void Add(Guid id, object value)
{
if (this.Contains(id))
{
throw new ArgumentException(SR.EPExists, "id");
throw new ArgumentException(SR.EPExists, nameof(id));
}

ExtendedProperty extendedProperty = new ExtendedProperty(id, value);
Expand All @@ -166,7 +166,7 @@ internal void Remove(Guid id)
{
if (!Contains(id))
{
throw new ArgumentException(SR.EPGuidNotFound, "id");
throw new ArgumentException(SR.EPGuidNotFound, nameof(id));
}

ExtendedProperty propertyToRemove = GetExtendedPropertyById(id);
Expand Down Expand Up @@ -226,7 +226,7 @@ internal object this[Guid attributeId]
ExtendedProperty ep = GetExtendedPropertyById(attributeId);
if (ep == null)
{
throw new ArgumentException(SR.EPNotFound, "attributeId");
throw new ArgumentException(SR.EPNotFound, nameof(attributeId));
}
return ep.Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal GestureRecognitionResult[] Recognize(StrokeCollection strokes)
ArgumentNullException.ThrowIfNull(strokes);
if (strokes.Count > 2)
{
throw new ArgumentException(SR.StrokeCollectionCountTooBig, "strokes");
throw new ArgumentException(SR.StrokeCollectionCountTooBig, nameof(strokes));
}

// Create an empty result.
Expand Down Expand Up @@ -207,7 +207,7 @@ internal static ApplicationGesture[] GetApplicationGestureArrayAndVerify(IEnumer
if (count == 0)
{
// An empty array is not allowed.
throw new ArgumentException(SR.ApplicationGestureArrayLengthIsZero, "applicationGestures");
throw new ArgumentException(SR.ApplicationGestureArrayLengthIsZero, nameof(applicationGestures));
}

bool foundAllGestures = false;
Expand All @@ -216,7 +216,7 @@ internal static ApplicationGesture[] GetApplicationGestureArrayAndVerify(IEnumer
{
if (!ApplicationGestureHelper.IsDefined(gesture))
{
throw new ArgumentException(SR.ApplicationGestureIsInvalid, "applicationGestures");
throw new ArgumentException(SR.ApplicationGestureIsInvalid, nameof(applicationGestures));
}

//check for allgestures
Expand All @@ -228,7 +228,7 @@ internal static ApplicationGesture[] GetApplicationGestureArrayAndVerify(IEnumer
//check for dupes
if (gestures.Contains(gesture))
{
throw new ArgumentException(SR.DuplicateApplicationGestureFound, "applicationGestures");
throw new ArgumentException(SR.DuplicateApplicationGestureFound, nameof(applicationGestures));
}

gestures.Add(gesture);
Expand All @@ -238,7 +238,7 @@ internal static ApplicationGesture[] GetApplicationGestureArrayAndVerify(IEnumer
if (foundAllGestures && gestures.Count != 1)
{
// no dupes allowed
throw new ArgumentException(SR.AllGesturesMustExistAlone, "applicationGestures");
throw new ArgumentException(SR.AllGesturesMustExistAlone, nameof(applicationGestures));
}

return gestures.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ internal static uint DecodeAsISF(Stream stream, uint cbSize, GuidList guidList,
cb = SerializationHelper.Decode(stream, out uiTag);
tag = (KnownTagCache.KnownTagIndex)uiTag;
if (cb > cbTotal)
throw new ArgumentException(SR.InvalidSizeSpecified, "cbSize");
throw new ArgumentException(SR.InvalidSizeSpecified, nameof(cbSize));

cbTotal -= cb;
cbRead += cb;
Expand All @@ -428,14 +428,14 @@ internal static uint DecodeAsISF(Stream stream, uint cbSize, GuidList guidList,

if (guid == Guid.Empty)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Custom Attribute tag embedded in ISF stream does not match guid table"), "tag");
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Custom Attribute tag embedded in ISF stream does not match guid table"), nameof(tag));
}

// Try and find the size
uint size = GuidList.GetDataSizeIfKnownGuid(guid);

if (size > cbTotal)
throw new ArgumentException(SR.InvalidSizeSpecified, "cbSize");
throw new ArgumentException(SR.InvalidSizeSpecified, nameof(cbSize));

// if the size is 0
if (0 == size)
Expand All @@ -455,7 +455,7 @@ internal static uint DecodeAsISF(Stream stream, uint cbSize, GuidList guidList,
uint bytesRead = (uint) stream.Read(bytes, 0, (int)cbInsize);
if (cbInsize != bytesRead)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Read different size from stream then expected"), "cbSize");
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Read different size from stream then expected"), nameof(cbSize));
}

cbRead += cbInsize;
Expand All @@ -476,7 +476,7 @@ internal static uint DecodeAsISF(Stream stream, uint cbSize, GuidList guidList,
uint bytesRead = (uint) stream.Read(bytes, 0, (int)size);
if (size != bytesRead)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Read different size from stream then expected"), "cbSize");
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Read different size from stream then expected"), nameof(cbSize));
}

using (MemoryStream subStream = new MemoryStream(bytes))
Expand Down Expand Up @@ -778,23 +778,23 @@ internal static void Validate(Guid id, object value)
{
if (!(value is System.Windows.Media.Color))
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(System.Windows.Media.Color)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(System.Windows.Media.Color)), nameof(value));
}
}
// int attributes
else if (id == KnownIds.CurveFittingError)
{
if (!(value.GetType() == typeof(int)))
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(int)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(int)), nameof(value));
}
}
else if (id == KnownIds.DrawingFlags)
{
// ignore validation of flags
if (value.GetType() != typeof(DrawingFlags))
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(DrawingFlags)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(DrawingFlags)), nameof(value));
}
}
else if (id == KnownIds.StylusTip)
Expand All @@ -805,11 +805,11 @@ internal static void Validate(Guid id, object value)

if ( !fStylusTipType && !fIntType )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(StylusTip), typeof(int)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(StylusTip), typeof(int)), nameof(value));
}
else if ( !StylusTipHelper.IsDefined((StylusTip)value) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueOfType, value, typeof(StylusTip)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueOfType, value, typeof(StylusTip)), nameof(value));
}
}
else if (id == KnownIds.StylusTipTransform)
Expand All @@ -820,37 +820,37 @@ internal static void Validate(Guid id, object value)
Type t = value.GetType();
if ( t != typeof(String) && t != typeof(Matrix) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(String), typeof(Matrix)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(String), typeof(Matrix)), nameof(value));
}
else if ( t == typeof(Matrix) )
{
Matrix matrix = (Matrix)value;
if ( !matrix.HasInverse )
{
throw new ArgumentException(SR.MatrixNotInvertible, "value");
throw new ArgumentException(SR.MatrixNotInvertible, nameof(value));
}
if ( MatrixHelper.ContainsNaN(matrix))
{
throw new ArgumentException(SR.InvalidMatrixContainsNaN, "value");
throw new ArgumentException(SR.InvalidMatrixContainsNaN, nameof(value));
}
if ( MatrixHelper.ContainsInfinity(matrix))
{
throw new ArgumentException(SR.InvalidMatrixContainsInfinity, "value");
throw new ArgumentException(SR.InvalidMatrixContainsInfinity, nameof(value));
}
}
}
else if (id == KnownIds.IsHighlighter)
{
if ( value.GetType() != typeof(bool))
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(bool)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(bool)), nameof(value));
}
}
else if ( id == KnownIds.StylusHeight || id == KnownIds.StylusWidth )
{
if ( value.GetType() != typeof(double) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(double)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(double)), nameof(value));
}

double dVal = (double)value;
Expand All @@ -859,22 +859,22 @@ internal static void Validate(Guid id, object value)
{
if ( Double.IsNaN(dVal) || dVal < DrawingAttributes.MinHeight || dVal > DrawingAttributes.MaxHeight)
{
throw new ArgumentOutOfRangeException("value", SR.InvalidDrawingAttributesHeight);
throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidDrawingAttributesHeight);
}
}
else
{
if (Double.IsNaN(dVal) || dVal < DrawingAttributes.MinWidth || dVal > DrawingAttributes.MaxWidth)
{
throw new ArgumentOutOfRangeException("value", SR.InvalidDrawingAttributesWidth);
throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidDrawingAttributesWidth);
}
}
}
else if ( id == KnownIds.Transparency )
{
if ( value.GetType() != typeof(byte) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(byte)), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(byte)), nameof(value));
}

double dVal = (double)value;
Expand All @@ -887,7 +887,7 @@ internal static void Validate(Guid id, object value)
// then it doesn't include embedded type information (it's always a byte array)
if ( value.GetType() != typeof(byte[]) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(byte[])), "value");
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(byte[])), nameof(value));
}
}
else
Expand Down
Loading