From 82fbdbdef222f6d034e19cea3159b176e4abd5c3 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 24 Jul 2019 13:14:01 -0400 Subject: [PATCH] Re-emable CA1507 (use nameof) (dotnet/corefx#39731) Commit migrated from https://github.com/dotnet/corefx/commit/c265373119bc0449d347862862b43de35a95b186 --- src/libraries/CodeAnalysis.ruleset | 1 - .../Xml/Linq/ComponentModel/XComponentModel.cs | 12 +++---- .../System.Data.OleDb/src/OleDbException.cs | 2 +- .../src/System/Xml/Core/XmlReaderSettings.cs | 42 +++++++++++----------- .../src/System/Xml/Core/XmlWriterSettings.cs | 14 ++++---- .../src/System/Xml/Serialization/CodeIdentifier.cs | 4 +-- .../JsonSerializerOptions.Converters.cs | 2 +- 7 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/libraries/CodeAnalysis.ruleset b/src/libraries/CodeAnalysis.ruleset index 01ddb68..7f7db82 100644 --- a/src/libraries/CodeAnalysis.ruleset +++ b/src/libraries/CodeAnalysis.ruleset @@ -32,7 +32,6 @@ - diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/MS/Internal/Xml/Linq/ComponentModel/XComponentModel.cs b/src/libraries/System.ComponentModel.TypeConverter/src/MS/Internal/Xml/Linq/ComponentModel/XComponentModel.cs index 118a432..c55d181 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/MS/Internal/Xml/Linq/ComponentModel/XComponentModel.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/MS/Internal/Xml/Linq/ComponentModel/XComponentModel.cs @@ -501,9 +501,9 @@ namespace MS.Internal.Xml.Linq.ComponentModel public XDeferredAxis(Func> func, XElement element, XName name) { if (func == null) - throw new ArgumentNullException("func"); + throw new ArgumentNullException(nameof(func)); if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); _func = func; this.element = element; this.name = name; @@ -524,7 +524,7 @@ namespace MS.Internal.Xml.Linq.ComponentModel get { if (expandedName == null) - throw new ArgumentNullException("expandedName"); + throw new ArgumentNullException(nameof(expandedName)); if (name == null) { name = expandedName; @@ -547,9 +547,9 @@ namespace MS.Internal.Xml.Linq.ComponentModel public XDeferredSingleton(Func func, XElement element, XName name) { if (func == null) - throw new ArgumentNullException("func"); + throw new ArgumentNullException(nameof(func)); if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); _func = func; this.element = element; this.name = name; @@ -560,7 +560,7 @@ namespace MS.Internal.Xml.Linq.ComponentModel get { if (expandedName == null) - throw new ArgumentNullException("expandedName"); + throw new ArgumentNullException(nameof(expandedName)); if (name == null) { name = expandedName; diff --git a/src/libraries/System.Data.OleDb/src/OleDbException.cs b/src/libraries/System.Data.OleDb/src/OleDbException.cs index a7e094f..0611715 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbException.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbException.cs @@ -40,7 +40,7 @@ namespace System.Data.OleDb { if (null == si) { - throw new ArgumentNullException("si"); + throw new ArgumentNullException(nameof(si)); } si.AddValue("oledbErrors", oledbErrors, typeof(OleDbErrorCollection)); base.GetObjectData(si, context); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReaderSettings.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReaderSettings.cs index c7e1fb4..f15dc20 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReaderSettings.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReaderSettings.cs @@ -83,7 +83,7 @@ namespace System.Xml } set { - CheckReadOnly("Async"); + CheckReadOnly(nameof(Async)); _useAsync = value; } } @@ -97,7 +97,7 @@ namespace System.Xml } set { - CheckReadOnly("NameTable"); + CheckReadOnly(nameof(NameTable)); _nameTable = value; } } @@ -113,7 +113,7 @@ namespace System.Xml { set { - CheckReadOnly("XmlResolver"); + CheckReadOnly(nameof(XmlResolver)); _xmlResolver = value; IsXmlResolverSet = true; } @@ -144,7 +144,7 @@ namespace System.Xml } set { - CheckReadOnly("LineNumberOffset"); + CheckReadOnly(nameof(LineNumberOffset)); _lineNumberOffset = value; } } @@ -157,7 +157,7 @@ namespace System.Xml } set { - CheckReadOnly("LinePositionOffset"); + CheckReadOnly(nameof(LinePositionOffset)); _linePositionOffset = value; } } @@ -171,7 +171,7 @@ namespace System.Xml } set { - CheckReadOnly("ConformanceLevel"); + CheckReadOnly(nameof(ConformanceLevel)); if ((uint)value > (uint)ConformanceLevel.Document) { @@ -189,7 +189,7 @@ namespace System.Xml } set { - CheckReadOnly("CheckCharacters"); + CheckReadOnly(nameof(CheckCharacters)); _checkCharacters = value; } } @@ -202,7 +202,7 @@ namespace System.Xml } set { - CheckReadOnly("MaxCharactersInDocument"); + CheckReadOnly(nameof(MaxCharactersInDocument)); if (value < 0) { throw new ArgumentOutOfRangeException(nameof(value)); @@ -219,7 +219,7 @@ namespace System.Xml } set { - CheckReadOnly("MaxCharactersFromEntities"); + CheckReadOnly(nameof(MaxCharactersFromEntities)); if (value < 0) { throw new ArgumentOutOfRangeException(nameof(value)); @@ -237,7 +237,7 @@ namespace System.Xml } set { - CheckReadOnly("IgnoreWhitespace"); + CheckReadOnly(nameof(IgnoreWhitespace)); _ignoreWhitespace = value; } } @@ -250,7 +250,7 @@ namespace System.Xml } set { - CheckReadOnly("IgnoreProcessingInstructions"); + CheckReadOnly(nameof(IgnoreProcessingInstructions)); _ignorePIs = value; } } @@ -263,7 +263,7 @@ namespace System.Xml } set { - CheckReadOnly("IgnoreComments"); + CheckReadOnly(nameof(IgnoreComments)); _ignoreComments = value; } } @@ -277,7 +277,7 @@ namespace System.Xml } set { - CheckReadOnly("ProhibitDtd"); + CheckReadOnly(nameof(ProhibitDtd)); _dtdProcessing = value ? DtdProcessing.Prohibit : DtdProcessing.Parse; } } @@ -290,7 +290,7 @@ namespace System.Xml } set { - CheckReadOnly("DtdProcessing"); + CheckReadOnly(nameof(DtdProcessing)); if ((uint)value > (uint)DtdProcessing.Parse) { @@ -308,7 +308,7 @@ namespace System.Xml } set { - CheckReadOnly("CloseInput"); + CheckReadOnly(nameof(CloseInput)); _closeInput = value; } } @@ -321,7 +321,7 @@ namespace System.Xml } set { - CheckReadOnly("ValidationType"); + CheckReadOnly(nameof(ValidationType)); // This introduces a dependency on the validation readers and along with that // on XmlSchema and so on. For AOT builds this brings in a LOT of code @@ -345,7 +345,7 @@ namespace System.Xml } set { - CheckReadOnly("ValidationFlags"); + CheckReadOnly(nameof(ValidationFlags)); if ((uint)value > (uint)(XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.ProcessIdentityConstraints | @@ -369,7 +369,7 @@ namespace System.Xml } set { - CheckReadOnly("Schemas"); + CheckReadOnly(nameof(Schemas)); _schemas = value; } } @@ -378,12 +378,12 @@ namespace System.Xml { add { - CheckReadOnly("ValidationEventHandler"); + CheckReadOnly(nameof(ValidationEventHandler)); _valEventHandler += value; } remove { - CheckReadOnly("ValidationEventHandler"); + CheckReadOnly(nameof(ValidationEventHandler)); _valEventHandler -= value; } } @@ -393,7 +393,7 @@ namespace System.Xml // public void Reset() { - CheckReadOnly("Reset"); + CheckReadOnly(nameof(Reset)); Initialize(); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriterSettings.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriterSettings.cs index 7ca70cf..f24fd0f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriterSettings.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriterSettings.cs @@ -375,7 +375,7 @@ namespace System.Xml } set { - CheckReadOnly("DoNotEscapeUriAttributes"); + CheckReadOnly(nameof(DoNotEscapeUriAttributes)); _doNotEscapeUriAttributes = value; } } @@ -388,7 +388,7 @@ namespace System.Xml } set { - CheckReadOnly("MergeCDataSections"); + CheckReadOnly(nameof(MergeCDataSections)); _mergeCDataSections = value; } } @@ -402,7 +402,7 @@ namespace System.Xml } set { - CheckReadOnly("MediaType"); + CheckReadOnly(nameof(MediaType)); _mediaType = value; } } @@ -416,7 +416,7 @@ namespace System.Xml } set { - CheckReadOnly("DocTypeSystem"); + CheckReadOnly(nameof(DocTypeSystem)); _docTypeSystem = value; } } @@ -430,7 +430,7 @@ namespace System.Xml } set { - CheckReadOnly("DocTypePublic"); + CheckReadOnly(nameof(DocTypePublic)); _docTypePublic = value; } } @@ -444,7 +444,7 @@ namespace System.Xml } set { - CheckReadOnly("Standalone"); + CheckReadOnly(nameof(Standalone)); _standalone = value; } } @@ -458,7 +458,7 @@ namespace System.Xml } set { - CheckReadOnly("AutoXmlDeclaration"); + CheckReadOnly(nameof(AutoXmlDeclaration)); _autoXmlDecl = value; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs index 81354ba..4b106c3 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs @@ -104,7 +104,7 @@ namespace System.Xml.Serialization // the given char is already a valid name character #if DEBUG // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe - if (!IsValid(c)) throw new ArgumentException(SR.Format(SR.XmlInternalErrorDetails, "Invalid identifier character " + ((Int16)c).ToString(CultureInfo.InvariantCulture)), "c"); + if (!IsValid(c)) throw new ArgumentException(SR.Format(SR.XmlInternalErrorDetails, "Invalid identifier character " + ((Int16)c).ToString(CultureInfo.InvariantCulture)), nameof(c)); #endif // First char cannot be a number @@ -155,7 +155,7 @@ namespace System.Xml.Serialization default: #if DEBUG // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe - throw new ArgumentException(SR.Format(SR.XmlInternalErrorDetails, "Unhandled category " + uc), "c"); + throw new ArgumentException(SR.Format(SR.XmlInternalErrorDetails, "Unhandled category " + uc), nameof(c)); #else return false; #endif diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs index 12980ec..d059708 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs @@ -157,7 +157,7 @@ namespace System.Text.Json converter = factory.GetConverterInternal(typeToConvert, this); if (converter == null || converter.TypeToConvert == null) { - throw new ArgumentNullException("typeToConvert"); + throw new ArgumentNullException(nameof(typeToConvert)); } } -- 2.7.4