Skip to content

Commit 210a7a9

Browse files
authored
Fix most violations of new CA1859 (#80335)
* Fix most violations of new CA1859 The analyzer recommends replacing uses of types with other types that could reduce overheads (e.g. `List<T>` instead of `IList<T>`). This fixes most of the violations we currently have of the rule, but it doesn't enable it yet because there are too many false positives; fixes for those are in-flight. Some of these replacements won't help with perf (e.g. using `ArgumentException` instead of `Exception` as the return type of a throw helper create method), but there's little harm to them, and some of them do avoid overheads like allocation (e.g. foreach'ing something typed as `Dictionary<>` instead of `IDictionary<>` will avoid an enumerator allocation, accessing `Count` on a `List<T>` instead of `IList<T>` will avoid an interface dispatch, etc.) * Fix mistaken replacement
1 parent 1630725 commit 210a7a9

File tree

237 files changed

+648
-710
lines changed

Some content is hidden

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

237 files changed

+648
-710
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static Assembly GetCallingAssembly()
8383
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AssemblyNative_GetEntryAssembly")]
8484
private static partial void GetEntryAssemblyNative(ObjectHandleOnStack retAssembly);
8585

86-
private static Assembly? GetEntryAssemblyInternal()
86+
private static RuntimeAssembly? GetEntryAssemblyInternal()
8787
{
8888
RuntimeAssembly? entryAssembly = null;
8989
GetEntryAssemblyNative(ObjectHandleOnStack.Create(ref entryAssembly));

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public override void EndScope()
403403
throw new NotSupportedException(SR.InvalidOperation_NotAllowedInDynamicMethod);
404404
}
405405

406-
private int GetMemberRefToken(MethodBase methodInfo, Type[]? optionalParameterTypes)
406+
private int GetMemberRefToken(MethodInfo methodInfo, Type[]? optionalParameterTypes)
407407
{
408408
Type[]? parameterTypes;
409409
Type[][]? requiredCustomModifiers;

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Generic;
5+
using System.Collections.ObjectModel;
56
using System.Diagnostics;
67
using System.Diagnostics.CodeAnalysis;
78
using System.Runtime.CompilerServices;
@@ -92,7 +93,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimePa
9293
return pcas.Count > 0 ? GetCombinedList(cad, ref pcas) : cad;
9394
}
9495

95-
private static IList<CustomAttributeData> GetCombinedList(IList<CustomAttributeData> customAttributes, ref RuntimeType.ListBuilder<Attribute> pseudoAttributes)
96+
private static ReadOnlyCollection<CustomAttributeData> GetCombinedList(IList<CustomAttributeData> customAttributes, ref RuntimeType.ListBuilder<Attribute> pseudoAttributes)
9697
{
9798
Debug.Assert(pseudoAttributes.Count != 0);
9899

src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public partial class AssemblyLoadContext
5454
internal static partial bool TraceSatelliteSubdirectoryPathProbed(string filePath, int hResult);
5555

5656
[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
57-
private Assembly InternalLoadFromPath(string? assemblyPath, string? nativeImagePath)
57+
private RuntimeAssembly InternalLoadFromPath(string? assemblyPath, string? nativeImagePath)
5858
{
5959
RuntimeAssembly? loadedAssembly = null;
6060
LoadFromPath(_nativeAssemblyLoadContext, assemblyPath, nativeImagePath, ObjectHandleOnStack.Create(ref loadedAssembly));

src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ internal static FieldInfo GetFieldInfo(RuntimeType? reflectedType, IRuntimeField
19951995
}
19961996

19971997
// Called internally
1998-
private static PropertyInfo GetPropertyInfo(RuntimeType reflectedType, int tkProperty)
1998+
private static RuntimePropertyInfo GetPropertyInfo(RuntimeType reflectedType, int tkProperty)
19991999
{
20002000
RuntimePropertyInfo property;
20012001
RuntimePropertyInfo[] candidates =
@@ -3166,7 +3166,7 @@ public override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo memb
31663166
throw CreateGetMemberWithSameMetadataDefinitionAsNotFoundException(member);
31673167
}
31683168

3169-
private static MemberInfo? GetMethodWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo method)
3169+
private static RuntimeMethodInfo? GetMethodWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo method)
31703170
{
31713171
RuntimeMethodInfo[] cache = runtimeType.Cache.GetMethodList(MemberListType.CaseSensitive, method.Name);
31723172

@@ -3182,7 +3182,7 @@ public override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo memb
31823182
return null;
31833183
}
31843184

3185-
private static MemberInfo? GetConstructorWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo constructor)
3185+
private static RuntimeConstructorInfo? GetConstructorWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo constructor)
31863186
{
31873187
RuntimeConstructorInfo[] cache = runtimeType.Cache.GetConstructorList(MemberListType.CaseSensitive, constructor.Name);
31883188

@@ -3198,7 +3198,7 @@ public override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo memb
31983198
return null;
31993199
}
32003200

3201-
private static MemberInfo? GetPropertyWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo property)
3201+
private static RuntimePropertyInfo? GetPropertyWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo property)
32023202
{
32033203
RuntimePropertyInfo[] cache = runtimeType.Cache.GetPropertyList(MemberListType.CaseSensitive, property.Name);
32043204

@@ -3214,7 +3214,7 @@ public override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo memb
32143214
return null;
32153215
}
32163216

3217-
private static MemberInfo? GetFieldWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo field)
3217+
private static RuntimeFieldInfo? GetFieldWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo field)
32183218
{
32193219
RuntimeFieldInfo[] cache = runtimeType.Cache.GetFieldList(MemberListType.CaseSensitive, field.Name);
32203220

@@ -3230,7 +3230,7 @@ public override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo memb
32303230
return null;
32313231
}
32323232

3233-
private static MemberInfo? GetEventWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo eventInfo)
3233+
private static RuntimeEventInfo? GetEventWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo eventInfo)
32343234
{
32353235
RuntimeEventInfo[] cache = runtimeType.Cache.GetEventList(MemberListType.CaseSensitive, eventInfo.Name);
32363236

@@ -3246,7 +3246,7 @@ public override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo memb
32463246
return null;
32473247
}
32483248

3249-
private static MemberInfo? GetNestedTypeWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo nestedType)
3249+
private static RuntimeType? GetNestedTypeWithSameMetadataDefinitionAs(RuntimeType runtimeType, MemberInfo nestedType)
32503250
{
32513251
RuntimeType[] cache = runtimeType.Cache.GetNestedTypeList(MemberListType.CaseSensitive, nestedType.Name);
32523252

src/libraries/Common/src/Interop/Windows/BCrypt/Cng.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using System.Text;
66
using System.Diagnostics;
77
using System.Runtime.InteropServices;
8+
using System.Security.Cryptography;
89

910
using Internal.Cryptography;
11+
using Microsoft.Win32.SafeHandles;
12+
1013
using static Interop;
1114
using static Interop.BCrypt;
12-
using Microsoft.Win32.SafeHandles;
1315

1416
namespace Internal.NativeCrypto
1517
{
@@ -112,7 +114,7 @@ public static void SetEffectiveKeyLength(this SafeAlgorithmHandle hAlg, int effe
112114
}
113115
}
114116

115-
private static Exception CreateCryptographicException(NTSTATUS ntStatus)
117+
private static CryptographicException CreateCryptographicException(NTSTATUS ntStatus)
116118
{
117119
int hr = ((int)ntStatus) | 0x01000000;
118120
return hr.ToCryptographicException();

src/libraries/Common/src/System/Security/Cryptography/RSAAndroid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ internal SafeRsaHandle DuplicateKeyHandle()
792792
return _key.Value.DuplicateHandle();
793793
}
794794

795-
private static Exception PaddingModeNotSupported() =>
795+
private static CryptographicException PaddingModeNotSupported() =>
796796
new CryptographicException(SR.Cryptography_InvalidPaddingMode);
797797
}
798798
}

src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ private static void ValidatePadding(RSASignaturePadding padding)
902902

903903
static partial void ThrowIfNotSupported();
904904

905-
private static Exception PaddingModeNotSupported() =>
905+
private static CryptographicException PaddingModeNotSupported() =>
906906
new CryptographicException(SR.Cryptography_InvalidPaddingMode);
907907
}
908908
}

src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ private static Array BindArray(Type type, IEnumerable? source, IConfiguration co
691691
elementType = type.GetGenericArguments()[0];
692692
}
693693

694-
IList list = new List<object?>();
694+
var list = new List<object?>();
695695

696696
if (source != null)
697697
{
@@ -727,7 +727,7 @@ private static Array BindArray(Type type, IEnumerable? source, IConfiguration co
727727
}
728728

729729
Array result = Array.CreateInstance(elementType, list.Count);
730-
list.CopyTo(result, 0);
730+
((IList)list).CopyTo(result, 0);
731731
return result;
732732
}
733733

@@ -976,7 +976,7 @@ private static List<PropertyInfo> GetAllProperties([DynamicallyAccessedMembers(D
976976
return propertyBindingPoint.Value;
977977
}
978978

979-
private static string GetPropertyName(MemberInfo property)
979+
private static string GetPropertyName(PropertyInfo property)
980980
{
981981
ThrowHelper.ThrowIfNull(property);
982982

src/libraries/Microsoft.Extensions.Configuration.Json/src/JsonConfigurationFileParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private JsonConfigurationFileParser() { }
1919
public static IDictionary<string, string?> Parse(Stream input)
2020
=> new JsonConfigurationFileParser().ParseStream(input);
2121

22-
private IDictionary<string, string?> ParseStream(Stream input)
22+
private Dictionary<string, string?> ParseStream(Stream input)
2323
{
2424
var jsonDocumentOptions = new JsonDocumentOptions
2525
{

src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private static void ReadAttributes(XmlReader reader, XmlConfigurationElement ele
245245
return name;
246246
}
247247

248-
private static IDictionary<string, string?> ProvideConfiguration(XmlConfigurationElement? root)
248+
private static Dictionary<string, string?> ProvideConfiguration(XmlConfigurationElement? root)
249249
{
250250
Dictionary<string, string?> configuration = new(StringComparer.OrdinalIgnoreCase);
251251

src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationRoot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.Extensions.Configuration
1414
public class ConfigurationRoot : IConfigurationRoot, IDisposable
1515
{
1616
private readonly IList<IConfigurationProvider> _providers;
17-
private readonly IList<IDisposable> _changeTokenRegistrations;
17+
private readonly List<IDisposable> _changeTokenRegistrations;
1818
private ConfigurationReloadToken _changeToken = new ConfigurationReloadToken();
1919

2020
/// <summary>

src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private static MethodInfo GetMethodInfo<T>(Expression<T> expr)
222222
return service;
223223
}
224224

225-
private static Expression BuildFactoryExpression(
225+
private static NewExpression BuildFactoryExpression(
226226
ConstructorInfo constructor,
227227
int?[] parameterMap,
228228
Expression serviceProvider,

src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private static CallSiteResultCacheLocation GetCommonCacheLocation(CallSiteResult
398398
return null;
399399
}
400400

401-
private ServiceCallSite CreateConstructorCallSite(
401+
private ConstructorCallSite CreateConstructorCallSite(
402402
ResultCache lifetime,
403403
Type serviceType,
404404
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType,

src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/Expressions/ExpressionResolverBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected override Expression VisitScopeCache(ServiceCallSite callSite, object?
201201
}
202202

203203
// Move off the main stack
204-
private Expression BuildScopedExpression(ServiceCallSite callSite)
204+
private ConditionalExpression BuildScopedExpression(ServiceCallSite callSite)
205205
{
206206
ConstantExpression callSiteExpression = Expression.Constant(
207207
callSite,

src/libraries/Microsoft.Extensions.DependencyModel/src/CompilationLibrary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public IEnumerable<string> ResolveReferencePaths(params ICompilationAssemblyReso
7171
return ResolveReferencePaths(DefaultResolver, assemblies);
7272
}
7373

74-
private IEnumerable<string> ResolveReferencePaths(ICompilationAssemblyResolver resolver, List<string> assemblies)
74+
private List<string> ResolveReferencePaths(ICompilationAssemblyResolver resolver, List<string> assemblies)
7575
{
7676
if (!resolver.TryResolveAssemblyPaths(this, assemblies))
7777
{

src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DependencyContextJsonReader : IDependencyContextReader
1717
private const int UnseekableStreamInitialRentSize = 4096;
1818
private static ReadOnlySpan<byte> Utf8Bom => new byte[] { 0xEF, 0xBB, 0xBF };
1919

20-
private readonly IDictionary<string, string> _stringPool = new Dictionary<string, string>();
20+
private readonly Dictionary<string, string> _stringPool = new Dictionary<string, string>();
2121

2222
public DependencyContext Read(Stream stream)
2323
{
@@ -448,7 +448,7 @@ private TargetLibrary ReadTargetLibrary(ref Utf8JsonReader reader, string target
448448
};
449449
}
450450

451-
private IEnumerable<Dependency> ReadTargetLibraryDependencies(ref Utf8JsonReader reader)
451+
private List<Dependency> ReadTargetLibraryDependencies(ref Utf8JsonReader reader)
452452
{
453453
var dependencies = new List<Dependency>();
454454

src/libraries/Microsoft.Extensions.DependencyModel/src/Utf8JsonReaderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static bool ReadAsBoolean(this ref Utf8JsonReader reader, bool defaultVal
132132
return reader.GetBoolean();
133133
}
134134

135-
private static Exception CreateUnexpectedException(ref Utf8JsonReader reader, string expected)
135+
private static FormatException CreateUnexpectedException(ref Utf8JsonReader reader, string expected)
136136
{
137137
// Replace with public API once https://github.com/dotnet/runtime/issues/28482 is fixed
138138
object boxedState = reader.CurrentState;

src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Patterns/PatternBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public IPattern Build(string pattern)
4141
var allSegments = new List<IPathSegment>();
4242
bool isParentSegmentLegal = true;
4343

44-
IList<IPathSegment>? segmentsPatternStartsWith = null;
45-
IList<IList<IPathSegment>>? segmentsPatternContains = null;
46-
IList<IPathSegment>? segmentsPatternEndsWith = null;
44+
List<IPathSegment>? segmentsPatternStartsWith = null;
45+
List<IList<IPathSegment>>? segmentsPatternContains = null;
46+
List<IPathSegment>? segmentsPatternEndsWith = null;
4747

4848
int endPattern = pattern.Length;
4949
for (int scanPattern = 0; scanPattern < endPattern;)

src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Matcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ namespace Microsoft.Extensions.FileSystemGlobbing
9696
/// </remarks>
9797
public class Matcher
9898
{
99-
private readonly IList<IPattern> _includePatterns = new List<IPattern>();
100-
private readonly IList<IPattern> _excludePatterns = new List<IPattern>();
99+
private readonly List<IPattern> _includePatterns = new List<IPattern>();
100+
private readonly List<IPattern> _excludePatterns = new List<IPattern>();
101101
private readonly PatternBuilder _builder;
102102
private readonly StringComparison _comparison;
103103

src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public async Task StopAsync(CancellationToken cancellationToken = default)
125125
// Trigger IHostApplicationLifetime.ApplicationStopping
126126
_applicationLifetime.StopApplication();
127127

128-
IList<Exception> exceptions = new List<Exception>();
128+
var exceptions = new List<Exception>();
129129
if (_hostedServices != null) // Started?
130130
{
131131
foreach (IHostedService hostedService in _hostedServices.Reverse())

src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal IEventLog EventLog
4040
set => _eventLog = value;
4141
}
4242

43-
private IEventLog CreateDefaultEventLog()
43+
private WindowsEventLog CreateDefaultEventLog()
4444
{
4545
string logName = string.IsNullOrEmpty(LogName) ? "Application" : LogName;
4646
string machineName = string.IsNullOrEmpty(MachineName) ? "." : MachineName;

src/libraries/Microsoft.NETCore.Platforms/src/GenerateRuntimeGraph.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private RuntimeGraph SafeMerge(RuntimeGraph existingGraph, RuntimeGroup runtimeG
292292
return RuntimeGraph.Merge(existingGraph, runtimeGraph);
293293
}
294294

295-
private void ValidateImports(RuntimeGraph runtimeGraph, IDictionary<string, string> externalRIDs)
295+
private void ValidateImports(RuntimeGraph runtimeGraph, Dictionary<string, string> externalRIDs)
296296
{
297297
foreach (var runtimeDescription in runtimeGraph.Runtimes.Values)
298298
{
@@ -328,7 +328,7 @@ private void AddRuntimeIdentifiers(ICollection<RuntimeGroup> runtimeGroups)
328328
}
329329
}
330330

331-
private static IDictionary<string, IEnumerable<string>> GetCompatibilityMap(RuntimeGraph graph)
331+
private static Dictionary<string, IEnumerable<string>> GetCompatibilityMap(RuntimeGraph graph)
332332
{
333333
Dictionary<string, IEnumerable<string>> compatibilityMap = new Dictionary<string, IEnumerable<string>>();
334334

@@ -350,7 +350,7 @@ private static IDictionary<string, IEnumerable<string>> ReadCompatibilityMap(str
350350
}
351351
}
352352

353-
private static void WriteCompatibilityMap(IDictionary<string, IEnumerable<string>> compatibilityMap, string mapFile)
353+
private static void WriteCompatibilityMap(Dictionary<string, IEnumerable<string>> compatibilityMap, string mapFile)
354354
{
355355
var serializer = new JsonSerializer()
356356
{

src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/Symbols.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
13761376
If declaringType.IsConstructedGenericType Then
13771377
declaringType = declaringType.GetGenericTypeDefinition
13781378
End If
1379-
Dim rawMethod As MethodBase = Nothing
1379+
Dim rawMethod As MethodInfo = Nothing
13801380
For Each candidate As MethodInfo In declaringType.GetTypeInfo.GetDeclaredMethods(item.Name)
13811381
If candidate.HasSameMetadataDefinitionAs(item) Then
13821382
rawMethod = candidate

src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public override IList<IEnumerator<KeyValuePair<long, TSource>>> GetOrderablePart
504504
IEnumerator<KeyValuePair<long, TSource>>[] partitions
505505
= new IEnumerator<KeyValuePair<long, TSource>>[partitionCount];
506506

507-
IEnumerable<KeyValuePair<long, TSource>> partitionEnumerable = new InternalPartitionEnumerable(_source.GetEnumerator(), _useSingleChunking, true);
507+
var partitionEnumerable = new InternalPartitionEnumerable(_source.GetEnumerator(), _useSingleChunking, true);
508508
for (int i = 0; i < partitionCount; i++)
509509
{
510510
partitions[i] = partitionEnumerable.GetEnumerator();

src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/StringCollection.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,10 @@ IEnumerator IEnumerable.GetEnumerator()
235235
public class StringEnumerator
236236
{
237237
private readonly System.Collections.IEnumerator _baseEnumerator;
238-
private readonly System.Collections.IEnumerable _temp;
239238

240239
internal StringEnumerator(StringCollection mappings)
241240
{
242-
_temp = (IEnumerable)(mappings);
243-
_baseEnumerator = _temp.GetEnumerator();
241+
_baseEnumerator = ((IEnumerable)mappings).GetEnumerator();
244242
}
245243

246244
public string? Current

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UIHintAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public override bool Equals([NotNullWhen(true)] object? obj)
159159
/// <returns>
160160
/// Dictionary of control parameters.
161161
/// </returns>
162-
private IDictionary<string, object?> BuildControlParametersDictionary()
162+
private Dictionary<string, object?> BuildControlParametersDictionary()
163163
{
164-
IDictionary<string, object?> controlParameters = new Dictionary<string, object?>();
164+
var controlParameters = new Dictionary<string, object?>();
165165

166166
object?[]? inputControlParameters = _inputControlParameters;
167167

0 commit comments

Comments
 (0)