Skip to content

Commit 54eed54

Browse files
authored
use target typed new when type is obvious (#6798)
1 parent 647815d commit 54eed54

File tree

557 files changed

+1569
-1634
lines changed

Some content is hidden

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

557 files changed

+1569
-1634
lines changed

src/benchmark/Akka.Benchmarks/Actor/ActorMessagingMemoryPressureBenchmark.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ActorMessagingMemoryPressureBenchmark
2121
public sealed class StopActor
2222
{
2323
private StopActor(){}
24-
public static readonly StopActor Instance = new StopActor();
24+
public static readonly StopActor Instance = new();
2525
}
2626

2727
public sealed class MyActor : ReceiveActor

src/benchmark/Akka.Benchmarks/Actor/ActorPathBenchmarks.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class ActorPathBenchmarks
1818
private ActorPath x;
1919
private ActorPath y;
2020
private ActorPath _childPath;
21-
private Address _sysAdr = new Address("akka.tcp", "system", "127.0.0.1", 1337);
22-
private Address _otherAdr = new Address("akka.tcp", "system", "127.0.0.1", 1338);
21+
private Address _sysAdr = new("akka.tcp", "system", "127.0.0.1", 1337);
22+
private Address _otherAdr = new("akka.tcp", "system", "127.0.0.1", 1338);
2323

2424
private string _actorPathStr;
2525

src/benchmark/Akka.Benchmarks/Actor/GetChildBenchmark.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ protected override void OnReceive(object message)
9393
private ActorSystem _system;
9494
private IActorRef _parentActor;
9595

96-
private ActorWithChild.Get _getMessage = new ActorWithChild.Get("food");
97-
private ActorWithChild.Create _createMessage = new ActorWithChild.Create("food");
96+
private ActorWithChild.Get _getMessage = new("food");
97+
private ActorWithChild.Create _createMessage = new("food");
9898

9999
private IActorContext _cell;
100100
private RepointableActorRef _repointableActorRef;
101101
private LocalActorRef _localActorRef;
102102
private VirtualPathContainer _virtualPathContainer;
103103

104-
private List<string> _rpChildQueryPath = new List<string>() { "food", "ood", "od" };
105-
private List<string> _lclChildQueryPath = new List<string>() { "ood", "od", "d" };
106-
private List<string> _virtualPathContainerQueryPath = new List<string>() { "foo" };
104+
private List<string> _rpChildQueryPath = new() { "food", "ood", "od" };
105+
private List<string> _lclChildQueryPath = new() { "ood", "od", "d" };
106+
private List<string> _virtualPathContainerQueryPath = new() { "foo" };
107107

108108
[GlobalSetup]
109109
public async Task Setup()

src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task Actor_ping_pong_single_pair_in_memory()
4949

5050
sealed class StartTest
5151
{
52-
public static readonly StartTest Instance = new StartTest();
52+
public static readonly StartTest Instance = new();
5353
private StartTest() { }
5454
}
5555

@@ -65,7 +65,7 @@ public Signal(int remaining)
6565

6666
sealed class TestDone
6767
{
68-
public static readonly TestDone Instance = new TestDone();
68+
public static readonly TestDone Instance = new();
6969
private TestDone() { }
7070
}
7171

src/benchmark/Akka.Benchmarks/Actor/SpawnActorBenchmarks.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ public StartTest(int actorCount) {
6666

6767
sealed class ChildReady
6868
{
69-
public static readonly ChildReady Instance = new ChildReady();
69+
public static readonly ChildReady Instance = new();
7070
private ChildReady() { }
7171
}
7272

7373
sealed class TestDone
7474
{
75-
public static readonly TestDone Instance = new TestDone();
75+
public static readonly TestDone Instance = new();
7676
private TestDone() { }
7777
}
7878

src/benchmark/Akka.Benchmarks/Cluster/ReachabilityBenchmarks.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public class ReachabilityBenchmarks
2727
[Params(100)]
2828
public int Iterations;
2929

30-
public Address Address = new Address("akka", "sys", "a", 2552);
31-
public Address Node = new Address("akka", "sys", "a", 2552);
30+
public Address Address = new("akka", "sys", "a", 2552);
31+
public Address Node = new("akka", "sys", "a", 2552);
3232

3333
private Reachability CreateReachabilityOfSize(Reachability baseReachability, int size)
3434
{

src/benchmark/Akka.Benchmarks/IO/TcpOperationsBenchmarks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public EchoConnection(IActorRef connection)
104104

105105
private class ClientCoordinator : ReceiveActor
106106
{
107-
private readonly HashSet<IActorRef> _waitingChildren = new HashSet<IActorRef>();
107+
private readonly HashSet<IActorRef> _waitingChildren = new();
108108
private IActorRef _requester;
109109

110110
public ClientCoordinator(string host, int port, int clientsCount)

src/benchmark/Akka.Benchmarks/Remoting/AkkaPduCodecBenchmark.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class AkkaPduCodecBenchmark
4848
/// </summary>
4949
private readonly object _message = "foobar";
5050

51-
private readonly Ack _lastAck = new Ack(-1);
51+
private readonly Ack _lastAck = new(-1);
5252

5353
private ByteString _fullDecode;
5454
private ByteString _pduDecoded;

src/benchmark/Akka.Cluster.Benchmarks/Persistence/JournalWriteBenchmarks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Akka.Cluster.Benchmarks.Persistence
2020
[Config(typeof(MicroBenchmarkConfig))]
2121
public class JournalWriteBenchmarks
2222
{
23-
private static readonly Store Message = new Store(1);
23+
private static readonly Store Message = new(1);
2424

2525
[Params(1, 10, 100)] public int PersistentActors;
2626

src/benchmark/Akka.Cluster.Benchmarks/Persistence/PersistenceInfrastructure.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ namespace Akka.Cluster.Benchmarks.Persistence
1717
{
1818
public sealed class Init
1919
{
20-
public static readonly Init Instance = new Init();
20+
public static readonly Init Instance = new();
2121
private Init() { }
2222
}
2323

2424
public sealed class Finish
2525
{
26-
public static readonly Finish Instance = new Finish();
26+
public static readonly Finish Instance = new();
2727
private Finish() { }
2828
}
2929

3030
public sealed class Done
3131
{
32-
public static readonly Done Instance = new Done();
32+
public static readonly Done Instance = new();
3333
private Done() { }
3434
}
3535

@@ -45,7 +45,7 @@ public Finished(long state)
4545

4646
public sealed class RecoveryFinished
4747
{
48-
public static readonly RecoveryFinished Instance = new RecoveryFinished();
48+
public static readonly RecoveryFinished Instance = new();
4949

5050
private RecoveryFinished() { }
5151
}
@@ -75,7 +75,7 @@ public Stored(int value)
7575
/// </summary>
7676
public sealed class IsFinished
7777
{
78-
public static readonly IsFinished Instance = new IsFinished();
78+
public static readonly IsFinished Instance = new();
7979
private IsFinished(){}
8080
}
8181

@@ -170,7 +170,7 @@ protected override bool ReceiveCommand(object message){
170170

171171

172172
public static class PersistenceInfrastructure{
173-
public static readonly AtomicCounter DbCounter = new AtomicCounter(0);
173+
public static readonly AtomicCounter DbCounter = new(0);
174174

175175
public static Config GenerateJournalConfig(){
176176
var config = ConfigurationFactory.ParseString(@"

src/benchmark/Akka.Cluster.Benchmarks/Sharding/HashCodeMessageExtractorBenchmarks.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Akka.Cluster.Benchmarks.Sharding
1414
[Config(typeof(MicroBenchmarkConfig))]
1515
public class HashCodeMessageExtractorBenchmarks
1616
{
17-
private ShardingEnvelope _m1 = new ShardingEnvelope("foo", 1);
18-
private ShardedMessage _m2 = new ShardedMessage("foo", 1);
17+
private ShardingEnvelope _m1 = new("foo", 1);
18+
private ShardedMessage _m2 = new("foo", 1);
1919
private IMessageExtractor _extractor = new ShardMessageExtractor();
2020

2121
[Benchmark]

src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardingInfrastructure.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class ShardedEntityActor : ReceiveActor
1717
{
1818
public sealed class Resolve
1919
{
20-
public static readonly Resolve Instance = new Resolve();
20+
public static readonly Resolve Instance = new();
2121
private Resolve(){}
2222
}
2323

@@ -211,7 +211,7 @@ public override string EntityId(object message)
211211

212212
public static class ShardingHelper
213213
{
214-
public static AtomicCounter DbId = new AtomicCounter(0);
214+
public static AtomicCounter DbId = new(0);
215215

216216
internal static string BoolToToggle(bool val)
217217
{

src/benchmark/Akka.Cluster.Cpu.Benchmark/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public static class Program
2727

2828
private const int DefaultWarmUpRepeat = 5;
2929

30-
private static readonly List<CpuUsage> Usages = new List<CpuUsage>();
31-
private static readonly List<Process> Processes = new List<Process>();
30+
private static readonly List<CpuUsage> Usages = new();
31+
private static readonly List<Process> Processes = new();
3232

3333
public static async Task<int> Main(string[] args)
3434
{

src/benchmark/RemotePingPong/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private class AllStartedActor : UntypedActor
228228
{
229229
public class AllStarted { }
230230

231-
private readonly HashSet<IActorRef> _actors = new HashSet<IActorRef>();
231+
private readonly HashSet<IActorRef> _actors = new();
232232
private int _correlationId = 0;
233233

234234
protected override void OnReceive(object message)

src/benchmark/SerializationBenchmarks/Program.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public JsonSerializerTests()
5555
_poolSer =
5656
_sys_pool.Serialization.FindSerializerForType(typeof(object));
5757
}
58-
private static TestSer testObj = new TestSer()
58+
private static TestSer testObj = new()
5959
{
6060
Id = 124,
6161
someStr =
@@ -123,8 +123,7 @@ public SerializationTests()
123123
_ser = _sys.Serialization.FindSerializerForType(typeof(MyType));
124124
}
125125

126-
public static MyType payload =>
127-
new MyType() { SomeInt = 1, SomeStr = "lol" };
126+
public static MyType payload => new() { SomeInt = 1, SomeStr = "lol" };
128127
[Benchmark]
129128
public void Serialization_WithTransport_NoState()
130129
{

src/contrib/cluster/Akka.Cluster.Metrics.Tests.MultiNode/ClustetMetricsRoutingSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class AdaptiveLoadBalancingRouterConfig : MultiNodeConfig
3333
public sealed class AllocateMemory
3434
{
3535
private AllocateMemory() { }
36-
public static readonly AllocateMemory Instance = new AllocateMemory();
36+
public static readonly AllocateMemory Instance = new();
3737
}
3838

3939
[Serializable]

src/contrib/cluster/Akka.Cluster.Metrics/ClusterMetricsCollector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ClusterMetricsCollector : ActorBase
3939
sealed class MetricsTick
4040
{
4141
private MetricsTick() { }
42-
public static readonly MetricsTick Instance = new MetricsTick();
42+
public static readonly MetricsTick Instance = new();
4343
}
4444

4545
/// <summary>
@@ -48,7 +48,7 @@ private MetricsTick() { }
4848
sealed class GossipTick
4949
{
5050
private GossipTick() { }
51-
public static readonly GossipTick Instance = new GossipTick();
51+
public static readonly GossipTick Instance = new();
5252
}
5353

5454
/// <summary>

src/contrib/cluster/Akka.Cluster.Metrics/ClusterMetricsSupervisor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private CollectionStartMessage(){ }
9595
/// <summary>
9696
/// Singleton instance for
9797
/// </summary>
98-
public static readonly CollectionStartMessage Instance = new CollectionStartMessage();
98+
public static readonly CollectionStartMessage Instance = new();
9999
}
100100

101101
/// <summary>
@@ -107,7 +107,7 @@ private CollectionStopMessage(){ }
107107
/// <summary>
108108
/// Singleton instance for
109109
/// </summary>
110-
public static readonly CollectionStopMessage Instance = new CollectionStopMessage();
110+
public static readonly CollectionStopMessage Instance = new();
111111
}
112112
}
113113
}

src/contrib/cluster/Akka.Cluster.Metrics/DateTimeExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Akka.Cluster.Metrics
1414
/// </summary>
1515
internal static class DateTimeExtensions
1616
{
17-
private static readonly DateTime UnixOffset = new DateTime(1970, 1, 1);
17+
private static readonly DateTime UnixOffset = new(1970, 1, 1);
1818

1919
/// <summary>
2020
/// Converts given date and time to UNIX Timestamp - number of milliseconds elapsed since 1 Jan 1970

src/contrib/cluster/Akka.Cluster.Metrics/Routing/MetricSelectors.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public class MemoryMetricsSelector : CapacityMetricsSelector
100100
/// <summary>
101101
/// Singleton instance
102102
/// </summary>
103-
public static readonly MemoryMetricsSelector Instance = new MemoryMetricsSelector();
104-
103+
public static readonly MemoryMetricsSelector Instance = new();
104+
105105
/// <inheritdoc />
106106
public override IImmutableDictionary<Actor.Address, double> Capacity(IImmutableSet<NodeMetrics> nodeMetrics)
107107
{
@@ -130,7 +130,7 @@ public class CpuMetricsSelector : CapacityMetricsSelector
130130
/// <summary>
131131
/// Singleton instance
132132
/// </summary>
133-
public static readonly CpuMetricsSelector Instance = new CpuMetricsSelector();
133+
public static readonly CpuMetricsSelector Instance = new();
134134

135135
public CpuMetricsSelector()
136136
{
@@ -198,7 +198,7 @@ public MixMetricsSelector(ImmutableArray<CapacityMetricsSelector> selectors) : b
198198
/// Singleton instance of the default MixMetricsSelector, which uses <see cref="MemoryMetricsSelector"/> and
199199
/// <see cref="CpuMetricsSelector"/>
200200
/// </summary>
201-
public static readonly MixMetricsSelector Instance = new MixMetricsSelector(
201+
public static readonly MixMetricsSelector Instance = new(
202202
ImmutableArray.Create<CapacityMetricsSelector>(
203203
MemoryMetricsSelector.Instance,
204204
CpuMetricsSelector.Instance)

src/contrib/cluster/Akka.Cluster.Metrics/Serialization/MetricsGossip.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed partial class MetricsGossip
2828
/// <summary>
2929
/// Empty metrics gossip
3030
/// </summary>
31-
public static readonly MetricsGossip Empty = new MetricsGossip(ImmutableHashSet<NodeMetrics>.Empty);
31+
public static readonly MetricsGossip Empty = new(ImmutableHashSet<NodeMetrics>.Empty);
3232

3333
public MetricsGossip(IImmutableSet<NodeMetrics> nodes)
3434
{

src/contrib/cluster/Akka.Cluster.Sharding.Tests.MultiNode/AsyncWriteProxyEx.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public abstract class AsyncWriteProxyEx : AsyncWriteJournal, IWithUnboundedStash
8686
{
8787
private class InitTimeout
8888
{
89-
public static readonly InitTimeout Instance = new InitTimeout();
89+
public static readonly InitTimeout Instance = new();
9090
private InitTimeout() { }
9191
}
9292

src/contrib/cluster/Akka.Cluster.Sharding.Tests.MultiNode/ClusterShardCoordinatorDowning2Spec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected override bool Receive(object message)
101101

102102
internal class GetLocations
103103
{
104-
public static readonly GetLocations Instance = new GetLocations();
104+
public static readonly GetLocations Instance = new();
105105

106106
private GetLocations()
107107
{

src/contrib/cluster/Akka.Cluster.Sharding.Tests.MultiNode/ClusterShardCoordinatorDowningSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected override bool Receive(object message)
103103

104104
internal class GetLocations
105105
{
106-
public static readonly GetLocations Instance = new GetLocations();
106+
public static readonly GetLocations Instance = new();
107107

108108
private GetLocations()
109109
{

src/contrib/cluster/Akka.Cluster.Sharding.Tests.MultiNode/ClusterShardingCustomShardAllocationSpec.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public abstract class ClusterShardingCustomShardAllocationSpec : MultiNodeCluste
7070

7171
internal class AllocateReq
7272
{
73-
public static readonly AllocateReq Instance = new AllocateReq();
73+
public static readonly AllocateReq Instance = new();
7474

7575
private AllocateReq()
7676
{
@@ -89,7 +89,7 @@ public UseRegion(IActorRef region)
8989

9090
internal class UseRegionAck
9191
{
92-
public static readonly UseRegionAck Instance = new UseRegionAck();
92+
public static readonly UseRegionAck Instance = new();
9393

9494
private UseRegionAck()
9595
{
@@ -98,7 +98,7 @@ private UseRegionAck()
9898

9999
internal class RebalanceReq
100100
{
101-
public static readonly RebalanceReq Instance = new RebalanceReq();
101+
public static readonly RebalanceReq Instance = new();
102102

103103
private RebalanceReq()
104104
{
@@ -117,7 +117,7 @@ public RebalanceShards(IImmutableSet<string> shards)
117117

118118
internal class RebalanceShardsAck
119119
{
120-
public static readonly RebalanceShardsAck Instance = new RebalanceShardsAck();
120+
public static readonly RebalanceShardsAck Instance = new();
121121

122122
private RebalanceShardsAck()
123123
{

0 commit comments

Comments
 (0)