Skip to content

Commit 54d15ab

Browse files
authored
Use nameof in more places (dotnet#30228)
I'd previously scrubbed the repo for places nameof could be used. A lot more code has come into the repo since then, so I'm rescrubbing.
1 parent 2b8294a commit 54d15ab

File tree

196 files changed

+1339
-1339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+1339
-1339
lines changed

src/Common/src/System/Data/ProviderBase/DbMetaDataFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ internal class DbMetaDataFactory
3636

3737
public DbMetaDataFactory(Stream xmlStream, string serverVersion, string normalizedServerVersion)
3838
{
39-
ADP.CheckArgumentNull(xmlStream, "xmlStream");
40-
ADP.CheckArgumentNull(serverVersion, "serverVersion");
41-
ADP.CheckArgumentNull(normalizedServerVersion, "normalizedServerVersion");
39+
ADP.CheckArgumentNull(xmlStream, nameof(xmlStream));
40+
ADP.CheckArgumentNull(serverVersion, nameof(serverVersion));
41+
ADP.CheckArgumentNull(normalizedServerVersion, nameof(normalizedServerVersion));
4242

4343
LoadDataSetFromXml(xmlStream);
4444

src/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ public static IntPtr CreateTimer(int interval)
518518
{
519519
if (interval <= 0)
520520
{
521-
throw new ArgumentException(SR.Format(SR.InvalidLowBoundArgument, "interval", interval.ToString(System.Threading.Thread.CurrentThread.CurrentCulture), "0"));
521+
throw new ArgumentException(SR.Format(SR.InvalidLowBoundArgument, nameof(interval), interval.ToString(System.Threading.Thread.CurrentThread.CurrentCulture), "0"));
522522
}
523523

524524
EnsureSystemEvents(true, true);

src/Microsoft.XmlSerializer.Generator/src/Sgen.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44
using System;
@@ -315,7 +315,7 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
315315
if (!force)
316316
{
317317
if (File.Exists(codePath))
318-
throw new InvalidOperationException(SR.Format(SR.ErrSerializerExists, codePath, "force"));
318+
throw new InvalidOperationException(SR.Format(SR.ErrSerializerExists, codePath, nameof(force)));
319319
}
320320

321321
if (Directory.Exists(codePath))
@@ -509,7 +509,7 @@ private static string GetXmlSerializerAssemblyName(Type type, string defaultName
509509
{
510510
if (type == null)
511511
{
512-
throw new ArgumentNullException("type");
512+
throw new ArgumentNullException(nameof(type));
513513
}
514514
return GetTempAssemblyName(type.Assembly.GetName(), defaultNamespace);
515515
}

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModel/AttributedModelDiscovery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static ReflectionComposablePart CreatePart(object attributedPart, Reflect
5353
var mappedType = reflectionContext.MapType(IntrospectionExtensions.GetTypeInfo(attributedPart.GetType()));
5454
if (mappedType.Assembly.ReflectionOnly)
5555
{
56-
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.Argument_ReflectionContextReturnsReflectionOnlyType, "reflectionContext"), "reflectionContext");
56+
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.Argument_ReflectionContextReturnsReflectionOnlyType, nameof(reflectionContext)), nameof(reflectionContext));
5757
}
5858

5959
ReflectionComposablePartDefinition definition = AttributedModelDiscovery.CreatePartDefinition(mappedType, PartCreationPolicyAttribute.Shared, true, (ICompositionElement)null);

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModelServices.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public static ComposablePart CreatePart(object attributedPart)
3636

3737
public static ComposablePart CreatePart(object attributedPart, ReflectionContext reflectionContext)
3838
{
39-
Requires.NotNull(attributedPart, "attributedPart");
40-
Requires.NotNull(reflectionContext, "reflectionContext");
39+
Requires.NotNull(attributedPart, nameof(attributedPart));
40+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
4141
Contract.Ensures(Contract.Result<ComposablePart>() != null);
4242

4343
return AttributedModelDiscovery.CreatePart(attributedPart, reflectionContext);
@@ -52,7 +52,7 @@ public static ComposablePart CreatePart(ComposablePartDefinition partDefinition,
5252
var reflectionComposablePartDefinition = partDefinition as ReflectionComposablePartDefinition;
5353
if(reflectionComposablePartDefinition == null)
5454
{
55-
throw ExceptionBuilder.CreateReflectionModelInvalidPartDefinition("partDefinition", partDefinition.GetType());
55+
throw ExceptionBuilder.CreateReflectionModelInvalidPartDefinition(nameof(partDefinition), partDefinition.GetType());
5656
}
5757

5858
return AttributedModelDiscovery.CreatePart(reflectionComposablePartDefinition, attributedPart);
@@ -160,7 +160,7 @@ public static ComposablePart AddPart(this CompositionBatch batch, object attribu
160160
public static void ComposeParts(this CompositionContainer container, params object[] attributedParts)
161161
{
162162
Requires.NotNull(container, nameof(container));
163-
Requires.NotNullOrNullElements(attributedParts, "attributedParts");
163+
Requires.NotNullOrNullElements(attributedParts, nameof(attributedParts));
164164

165165
CompositionBatch batch = new CompositionBatch(
166166
attributedParts.Select(attributedPart => AttributedModelServices.CreatePart(attributedPart)).ToArray(),
@@ -217,9 +217,9 @@ public static ComposablePart SatisfyImportsOnce(this ICompositionService composi
217217
/// </exception>
218218
public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart, ReflectionContext reflectionContext)
219219
{
220-
Requires.NotNull(compositionService, "compositionService");
221-
Requires.NotNull(attributedPart, "attributedPart");
222-
Requires.NotNull(reflectionContext, "reflectionContext");
220+
Requires.NotNull(compositionService, nameof(compositionService));
221+
Requires.NotNull(attributedPart, nameof(attributedPart));
222+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
223223
Contract.Ensures(Contract.Result<ComposablePart>() != null);
224224

225225
ComposablePart part = AttributedModelServices.CreatePart(attributedPart, reflectionContext);

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CatalogReflectionContextAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class CatalogReflectionContextAttribute : Attribute
2222

2323
public CatalogReflectionContextAttribute(Type reflectionContextType)
2424
{
25-
Requires.NotNull(reflectionContextType, "reflectionContextType");
25+
Requires.NotNull(reflectionContextType, nameof(reflectionContextType));
2626

2727
_reflectionContextType = reflectionContextType;
2828
}

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public CompositionException(IEnumerable<CompositionError> errors)
9494
internal CompositionException(string message, Exception innerException, IEnumerable<CompositionError> errors)
9595
: base(message, innerException)
9696
{
97-
Requires.NullOrNotNullElements(errors, "errors");
97+
Requires.NullOrNotNullElements(errors, nameof(errors));
9898
_errors = new ReadOnlyCollection<CompositionError>(errors == null ? Array.Empty<CompositionError>() : errors.ToArray<CompositionError>());
9999
}
100100

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ExportFactoryOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public ExportFactory(Func<Tuple<T, Action>> exportLifetimeContextCreator)
1212
{
1313
if (exportLifetimeContextCreator == null)
1414
{
15-
throw new ArgumentNullException("exportLifetimeContextCreator");
15+
throw new ArgumentNullException(nameof(exportLifetimeContextCreator));
1616
}
1717

1818
_exportLifetimeContextCreator = exportLifetimeContextCreator;

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public AggregateCatalog(params ComposablePartCatalog[] catalogs)
6464
/// </exception>
6565
public AggregateCatalog(IEnumerable<ComposablePartCatalog> catalogs)
6666
{
67-
Requires.NullOrNotNullElements(catalogs, "catalogs");
67+
Requires.NullOrNotNullElements(catalogs, nameof(catalogs));
6868

6969
_catalogs = new ComposablePartCatalogCollection(catalogs, OnChanged, OnChanging);
7070
}

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public AggregateExportProvider(params ExportProvider[] providers)
4949
ExportProvider provider = providers[i];
5050
if (provider == null)
5151
{
52-
throw ExceptionBuilder.CreateContainsNullElement("providers");
52+
throw ExceptionBuilder.CreateContainsNullElement(nameof(providers));
5353
}
5454

5555
copiedProviders[i] = provider;

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ApplicationCatalog.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ public ApplicationCatalog() {}
2626

2727
public ApplicationCatalog(ICompositionElement definitionOrigin)
2828
{
29-
Requires.NotNull(definitionOrigin, "definitionOrigin");
29+
Requires.NotNull(definitionOrigin, nameof(definitionOrigin));
3030

3131
_definitionOrigin = definitionOrigin;
3232
}
3333

3434
public ApplicationCatalog(ReflectionContext reflectionContext)
3535
{
36-
Requires.NotNull(reflectionContext, "reflectionContext");
36+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
3737

3838
_reflectionContext = reflectionContext;
3939
}
4040

4141
public ApplicationCatalog(ReflectionContext reflectionContext, ICompositionElement definitionOrigin)
4242
{
43-
Requires.NotNull(reflectionContext, "reflectionContext");
44-
Requires.NotNull(definitionOrigin, "definitionOrigin");
43+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
44+
Requires.NotNull(definitionOrigin, nameof(definitionOrigin));
4545

4646
_reflectionContext = reflectionContext;
4747
_definitionOrigin = definitionOrigin;
@@ -158,7 +158,7 @@ public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> G
158158
{
159159
ThrowIfDisposed();
160160

161-
Requires.NotNull(definition, "definition");
161+
Requires.NotNull(definition, nameof(definition));
162162

163163
return InnerCatalog.GetExports(definition);
164164
}

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class AssemblyCatalog : ComposablePartCatalog, ICompositionElement
7474
/// </remarks>
7575
public AssemblyCatalog(string codeBase)
7676
{
77-
Requires.NotNullOrEmpty(codeBase, "codeBase");
77+
Requires.NotNullOrEmpty(codeBase, nameof(codeBase));
7878

7979
InitializeAssemblyCatalog(LoadAssembly(codeBase));
8080
_definitionOrigin = this;
@@ -130,8 +130,8 @@ public AssemblyCatalog(string codeBase)
130130
/// </remarks>
131131
public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext)
132132
{
133-
Requires.NotNullOrEmpty(codeBase, "codeBase");
134-
Requires.NotNull(reflectionContext, "reflectionContext");
133+
Requires.NotNullOrEmpty(codeBase, nameof(codeBase));
134+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
135135

136136
InitializeAssemblyCatalog(LoadAssembly(codeBase));
137137
_reflectionContext = reflectionContext;
@@ -187,7 +187,7 @@ public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext)
187187
/// </remarks>
188188
public AssemblyCatalog(string codeBase, ICompositionElement definitionOrigin)
189189
{
190-
Requires.NotNullOrEmpty(codeBase, "codeBase");
190+
Requires.NotNullOrEmpty(codeBase, nameof(codeBase));
191191
Requires.NotNull(definitionOrigin, nameof(definitionOrigin));
192192

193193
InitializeAssemblyCatalog(LoadAssembly(codeBase));
@@ -251,9 +251,9 @@ public AssemblyCatalog(string codeBase, ICompositionElement definitionOrigin)
251251
/// </remarks>
252252
public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext, ICompositionElement definitionOrigin)
253253
{
254-
Requires.NotNullOrEmpty(codeBase, "codeBase");
255-
Requires.NotNull(reflectionContext, "reflectionContext");
256-
Requires.NotNull(definitionOrigin, "definitionOrigin");
254+
Requires.NotNullOrEmpty(codeBase, nameof(codeBase));
255+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
256+
Requires.NotNull(definitionOrigin, nameof(definitionOrigin));
257257

258258
InitializeAssemblyCatalog(LoadAssembly(codeBase));
259259
_reflectionContext = reflectionContext;
@@ -285,8 +285,8 @@ public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext, ICo
285285
/// </exception>
286286
public AssemblyCatalog(Assembly assembly, ReflectionContext reflectionContext)
287287
{
288-
Requires.NotNull(assembly, "assembly");
289-
Requires.NotNull(reflectionContext, "reflectionContext");
288+
Requires.NotNull(assembly, nameof(assembly));
289+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
290290

291291
InitializeAssemblyCatalog(assembly);
292292
_reflectionContext = reflectionContext;
@@ -325,9 +325,9 @@ public AssemblyCatalog(Assembly assembly, ReflectionContext reflectionContext)
325325
/// </exception>
326326
public AssemblyCatalog(Assembly assembly, ReflectionContext reflectionContext, ICompositionElement definitionOrigin)
327327
{
328-
Requires.NotNull(assembly, "assembly");
329-
Requires.NotNull(reflectionContext, "reflectionContext");
330-
Requires.NotNull(definitionOrigin, "definitionOrigin");
328+
Requires.NotNull(assembly, nameof(assembly));
329+
Requires.NotNull(reflectionContext, nameof(reflectionContext));
330+
Requires.NotNull(definitionOrigin, nameof(definitionOrigin));
331331

332332
InitializeAssemblyCatalog(assembly);
333333
_reflectionContext = reflectionContext;
@@ -392,7 +392,7 @@ private void InitializeAssemblyCatalog(Assembly assembly)
392392
{
393393
if (assembly.ReflectionOnly)
394394
{
395-
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.Argument_AssemblyReflectionOnly, "assembly"), "assembly");
395+
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.Argument_AssemblyReflectionOnly, nameof(assembly)), nameof(assembly));
396396
}
397397
_assembly = assembly;
398398
}
@@ -553,7 +553,7 @@ private string GetDisplayName()
553553

554554
private static Assembly LoadAssembly(string codeBase)
555555
{
556-
Requires.NotNullOrEmpty(codeBase, "codeBase");
556+
Requires.NotNullOrEmpty(codeBase, nameof(codeBase));
557557

558558
AssemblyName assemblyName;
559559

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CatalogExportProvider.FactoryExport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ public override object GetExportedValue(ExportDefinition definition)
117117
{
118118
if (definition != _definition.FactoryExportDefinition)
119119
{
120-
throw ExceptionBuilder.CreateExportDefinitionNotOnThisComposablePart("definition");
120+
throw ExceptionBuilder.CreateExportDefinitionNotOnThisComposablePart(nameof(definition));
121121
}
122122

123123
return _export.Value;
124124
}
125125

126126
public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
127127
{
128-
throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart("definition");
128+
throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart(nameof(definition));
129129
}
130130

131131
public void Dispose()

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public CatalogExportProvider(ComposablePartCatalog catalog, CompositionOptions c
7575
Requires.NotNull(catalog, nameof(catalog));
7676
if (compositionOptions > (CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService))
7777
{
78-
throw new ArgumentOutOfRangeException("compositionOptions");
78+
throw new ArgumentOutOfRangeException(nameof(compositionOptions));
7979
}
8080

8181
_catalog = catalog;

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ComposablePartExportProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ComposablePartExportProvider(CompositionOptions compositionOptions)
4040
{
4141
if (compositionOptions > (CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService))
4242
{
43-
throw new ArgumentOutOfRangeException("compositionOptions");
43+
throw new ArgumentOutOfRangeException(nameof(compositionOptions));
4444
}
4545

4646
_compositionOptions = compositionOptions;

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionBatch.SingleExportComposablePart.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override object GetExportedValue(ExportDefinition definition)
4444

4545
if (definition != _export.Definition)
4646
{
47-
throw ExceptionBuilder.CreateExportDefinitionNotOnThisComposablePart("definition");
47+
throw ExceptionBuilder.CreateExportDefinitionNotOnThisComposablePart(nameof(definition));
4848
}
4949

5050
return _export.Value;
@@ -53,9 +53,9 @@ public override object GetExportedValue(ExportDefinition definition)
5353
public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
5454
{
5555
Requires.NotNull(definition, nameof(definition));
56-
Requires.NotNullOrNullElements(exports, "exports");
56+
Requires.NotNullOrNullElements(exports, nameof(exports));
5757

58-
throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart("definition");
58+
throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart(nameof(definition));
5959
}
6060
}
6161
}

src/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionBatch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public CompositionBatch(IEnumerable<ComposablePart> partsToAdd, IEnumerable<Comp
4242
{
4343
if (part == null)
4444
{
45-
throw ExceptionBuilder.CreateContainsNullElement("partsToAdd");
45+
throw ExceptionBuilder.CreateContainsNullElement(nameof(partsToAdd));
4646
}
4747
_partsToAdd.Add(part);
4848
}
@@ -56,7 +56,7 @@ public CompositionBatch(IEnumerable<ComposablePart> partsToAdd, IEnumerable<Comp
5656
{
5757
if (part == null)
5858
{
59-
throw ExceptionBuilder.CreateContainsNullElement("partsToRemove");
59+
throw ExceptionBuilder.CreateContainsNullElement(nameof(partsToRemove));
6060
}
6161
_partsToRemove.Add(part);
6262
}

0 commit comments

Comments
 (0)