Skip to content

Commit 3fd5aa5

Browse files
authored
Use simplified new() form for field initialization (#289)
1 parent 5390e89 commit 3fd5aa5

File tree

88 files changed

+200
-200
lines changed

Some content is hidden

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

88 files changed

+200
-200
lines changed

Src/Microsoft.Dynamic/Actions/Argument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct Argument : IEquatable<Argument> {
1616
private readonly ArgumentType _kind;
1717
private readonly string _name;
1818

19-
public static readonly Argument Simple = new Argument(ArgumentType.Simple, null);
19+
public static readonly Argument Simple = new(ArgumentType.Simple, null);
2020

2121
public ArgumentType Kind => _kind;
2222
public string Name => _name;

Src/Microsoft.Dynamic/Actions/Calls/DefaultOverloadResolver.cs

Lines changed: 2 additions & 2 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 Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

@@ -37,7 +37,7 @@ public class DefaultOverloadResolver : OverloadResolver {
3737
private readonly CallSignature _signature;
3838
private readonly CallTypes _callType;
3939
private DynamicMetaObject _invalidSplattee;
40-
private static readonly DefaultOverloadResolverFactory _factory = new DefaultOverloadResolverFactory(DefaultBinder.Instance);
40+
private static readonly DefaultOverloadResolverFactory _factory = new(DefaultBinder.Instance);
4141

4242
// instance method call:
4343
public DefaultOverloadResolver(ActionBinder binder, DynamicMetaObject instance, IList<DynamicMetaObject> args, CallSignature signature)

Src/Microsoft.Dynamic/Actions/Calls/TypeInferer.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 Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

@@ -344,8 +344,8 @@ private static void CollectGenericParameters(Type type, List<Type> containedGenA
344344
/// z would be a ConstructedParameterInferer.
345345
/// </summary>
346346
private class ArgumentInputs {
347-
private readonly List<Type>/*!*/ _parameterTypes = new List<Type>();
348-
private readonly List<DynamicMetaObject>/*!*/ _inputs = new List<DynamicMetaObject>();
347+
private readonly List<Type>/*!*/ _parameterTypes = new();
348+
private readonly List<DynamicMetaObject>/*!*/ _inputs = new();
349349
private readonly Type/*!*/ _genericParam;
350350

351351
public ArgumentInputs(Type/*!*/ genericParam) {

Src/Microsoft.Dynamic/Actions/ConditionalBuilder.cs

Lines changed: 4 additions & 4 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 Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

@@ -19,9 +19,9 @@ namespace Microsoft.Scripting.Actions {
1919
/// branch must be added.
2020
/// </summary>
2121
class ConditionalBuilder {
22-
private readonly List<Expression> _conditions = new List<Expression>();
23-
private readonly List<Expression> _bodies = new List<Expression>();
24-
private readonly List<ParameterExpression> _variables = new List<ParameterExpression>();
22+
private readonly List<Expression> _conditions = new();
23+
private readonly List<Expression> _bodies = new();
24+
private readonly List<ParameterExpression> _variables = new();
2525
private Expression _body;
2626
private bool _isError;
2727
private BindingRestrictions _restrictions = BindingRestrictions.Empty;

Src/Microsoft.Dynamic/Actions/DefaultBinder.DeleteMember.cs

Lines changed: 2 additions & 2 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 Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

@@ -118,7 +118,7 @@ private bool MakeOperatorDeleteMemberBody(SetOrDeleteMemberInfo delInfo, Dynamic
118118
private sealed class SetOrDeleteMemberInfo {
119119
public readonly string Name;
120120
public readonly OverloadResolverFactory ResolutionFactory;
121-
public readonly ConditionalBuilder Body = new ConditionalBuilder();
121+
public readonly ConditionalBuilder Body = new();
122122

123123
public SetOrDeleteMemberInfo(string name, OverloadResolverFactory resolutionFactory) {
124124
Name = name;

Src/Microsoft.Dynamic/Actions/DefaultBinder.GetMember.cs

Lines changed: 2 additions & 2 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 Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

@@ -387,7 +387,7 @@ private sealed class GetMemberInfo {
387387
public readonly string Name;
388388
public readonly OverloadResolverFactory ResolutionFactory;
389389
public readonly bool IsNoThrow;
390-
public readonly ConditionalBuilder Body = new ConditionalBuilder();
390+
public readonly ConditionalBuilder Body = new();
391391
public readonly DynamicMetaObject ErrorSuggestion;
392392

393393
public GetMemberInfo(string name, OverloadResolverFactory resolutionFactory, bool noThrow, DynamicMetaObject errorSuggestion) {

Src/Microsoft.Dynamic/Actions/DefaultBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Scripting.Actions {
2323
/// </summary>
2424
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
2525
public partial class DefaultBinder : ActionBinder {
26-
internal static readonly DefaultBinder Instance = new DefaultBinder();
26+
internal static readonly DefaultBinder Instance = new();
2727

2828
public override bool CanConvertFrom(Type fromType, Type toType, bool toNotNullable, NarrowingLevel level) {
2929
return toType.IsAssignableFrom(fromType);

Src/Microsoft.Dynamic/Actions/EventTracker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class EventTracker : MemberTracker {
2323
// Each pair in the list holds on the stub handler that was added to the event delegate chain and the callable
2424
// object that is passed to +=/-= operators.
2525
private WeakDictionary<object, NormalHandlerList> _handlerLists;
26-
private static readonly object _staticTarget = new object();
26+
private static readonly object _staticTarget = new();
2727

2828
private readonly EventInfo _eventInfo;
2929
private MethodInfo _addMethod;
@@ -222,7 +222,7 @@ private sealed class ComHandlerList : HandlerList {
222222
/// <summary>
223223
/// Storage for the handlers - a key value pair of the callable object and the delegate handler.
224224
/// </summary>
225-
private readonly CopyOnWriteList<KeyValuePair<object, object>> _handlers = new CopyOnWriteList<KeyValuePair<object, object>>();
225+
private readonly CopyOnWriteList<KeyValuePair<object, object>> _handlers = new();
226226

227227
public override void AddHandler(object callableObject, Delegate handler) {
228228
Assert.NotNull(handler);
@@ -254,7 +254,7 @@ private sealed class NormalHandlerList : HandlerList {
254254
/// delegate will stay alive and so will the callable object. That means it's fine to have a weak reference
255255
/// to both of these objects.
256256
/// </summary>
257-
private readonly CopyOnWriteList<KeyValuePair<WeakReference, WeakReference>> _handlers = new CopyOnWriteList<KeyValuePair<WeakReference, WeakReference>>();
257+
private readonly CopyOnWriteList<KeyValuePair<WeakReference, WeakReference>> _handlers = new();
258258

259259
public override void AddHandler(object callableObject, Delegate handler) {
260260
Assert.NotNull(handler);

Src/Microsoft.Dynamic/Actions/MemberGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Scripting.Actions {
2525
/// </summary>
2626
public class MemberGroup : IEnumerable<MemberTracker> {
2727
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
28-
public static readonly MemberGroup EmptyGroup = new MemberGroup(MemberTracker.EmptyTrackers);
28+
public static readonly MemberGroup EmptyGroup = new(MemberTracker.EmptyTrackers);
2929

3030
private readonly MemberTracker[] _members;
3131

Src/Microsoft.Dynamic/Actions/MemberTracker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public abstract class MemberTracker {
2626
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")]
2727
public static readonly MemberTracker[] EmptyTrackers = Array.Empty<MemberTracker>();
2828

29-
private static readonly Dictionary<MemberKey, MemberTracker> _trackers = new Dictionary<MemberKey, MemberTracker>();
29+
private static readonly Dictionary<MemberKey, MemberTracker> _trackers = new();
3030

3131
/// <summary>
3232
/// We ensure we only produce one MemberTracker for each member which logically lives on the declaring type. So
3333
/// for example if you get a member from a derived class which is declared on the base class it should be the same
34-
/// as getting the member from the base class. Thats easy enough until you get into extension members here there
34+
/// as getting the member from the base class. That's easy enough until you get into extension members – here there
3535
/// might be one extension member which is being applied to multiple types. Therefore we need to take into account the
3636
/// extension type when ensuring that we only have 1 MemberTracker ever created.
3737
/// </summary>

0 commit comments

Comments
 (0)