Skip to content

Commit 29b1513

Browse files
authored
remove some casts (#6710)
1 parent 24dec7f commit 29b1513

File tree

101 files changed

+390
-471
lines changed

Some content is hidden

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

101 files changed

+390
-471
lines changed

src/contrib/cluster/Akka.Cluster.Tools/PublishSubscribe/Internal/TopicMessages.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public override bool Equals(object obj)
424424
{
425425
if (ReferenceEquals(null, obj)) return false;
426426
if (ReferenceEquals(this, obj)) return true;
427-
return obj is SendToOneSubscriber && Equals((SendToOneSubscriber)obj);
427+
return obj is SendToOneSubscriber subscriber && Equals(subscriber);
428428
}
429429

430430
public override int GetHashCode()

src/contrib/cluster/Akka.DistributedData/Durable/Messages.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public override bool Equals(object obj)
125125
{
126126
if (ReferenceEquals(null, obj)) return false;
127127
if (ReferenceEquals(this, obj)) return true;
128-
return obj is DurableDataEnvelope && Equals((DurableDataEnvelope) obj);
128+
return obj is DurableDataEnvelope envelope && Equals(envelope);
129129
}
130130
}
131131
}

src/contrib/cluster/Akka.DistributedData/Flag.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public bool Equals(Flag other)
6565
}
6666

6767

68-
public override bool Equals(object obj) => obj is Flag && Equals((Flag) obj);
68+
public override bool Equals(object obj) => obj is Flag flag && Equals(flag);
6969

7070
public override int GetHashCode() => Enabled.GetHashCode();
7171

72-
public int CompareTo(object obj) => obj is Flag ? CompareTo((Flag) obj) : 1;
72+
public int CompareTo(object obj) => obj is Flag flag ? CompareTo(flag) : 1;
7373

7474
public int CompareTo(Flag other) => other == null ? 1 : Enabled.CompareTo(other.Enabled);
7575

src/contrib/cluster/Akka.DistributedData/GSet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public bool Equals(GSet<T> other)
162162
public IEnumerator<T> GetEnumerator() => Elements.GetEnumerator();
163163

164164

165-
public override bool Equals(object obj) => obj is GSet<T> && Equals((GSet<T>)obj);
165+
public override bool Equals(object obj) => obj is GSet<T> set && Equals(set);
166166

167167

168168
public override int GetHashCode()

src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public bool Equals(Write other)
137137
}
138138

139139
/// <inheritdoc/>
140-
public override bool Equals(object obj) => obj is Write && Equals((Write)obj);
140+
public override bool Equals(object obj) => obj is Write write && Equals(write);
141141

142142
/// <inheritdoc/>
143143
public override int GetHashCode()
@@ -245,7 +245,7 @@ public bool Equals(Read other)
245245
}
246246

247247
/// <inheritdoc/>
248-
public override bool Equals(object obj) => obj is Read && Equals((Read)obj);
248+
public override bool Equals(object obj) => obj is Read read && Equals(read);
249249

250250
/// <inheritdoc/>
251251
public override int GetHashCode() => Key?.GetHashCode() ?? 0;
@@ -284,7 +284,7 @@ public bool Equals(ReadResult other)
284284
}
285285

286286
/// <inheritdoc/>
287-
public override bool Equals(object obj) => obj is ReadResult && Equals((ReadResult)obj);
287+
public override bool Equals(object obj) => obj is ReadResult result && Equals(result);
288288

289289
/// <inheritdoc/>
290290
public override int GetHashCode() => Envelope?.GetHashCode() ?? 0;
@@ -329,7 +329,7 @@ public bool Equals(ReadRepair other)
329329
}
330330

331331
/// <inheritdoc/>
332-
public override bool Equals(object obj) => obj is ReadRepair && Equals((ReadRepair)obj);
332+
public override bool Equals(object obj) => obj is ReadRepair repair && Equals(repair);
333333

334334
/// <inheritdoc/>
335335
public override int GetHashCode()
@@ -715,7 +715,7 @@ public bool Equals(Status other)
715715
}
716716

717717
/// <inheritdoc/>
718-
public override bool Equals(object obj) => obj is Status && Equals((Status)obj);
718+
public override bool Equals(object obj) => obj is Status status && Equals(status);
719719

720720
/// <inheritdoc/>
721721
public override int GetHashCode()
@@ -795,7 +795,7 @@ public bool Equals(Gossip other)
795795
}
796796

797797
/// <inheritdoc/>
798-
public override bool Equals(object obj) => obj is Gossip && Equals((Gossip)obj);
798+
public override bool Equals(object obj) => obj is Gossip gossip && Equals(gossip);
799799

800800
/// <inheritdoc/>
801801
public override int GetHashCode()
@@ -847,7 +847,7 @@ public override bool Equals(object obj)
847847
{
848848
if (ReferenceEquals(null, obj)) return false;
849849
if (ReferenceEquals(this, obj)) return true;
850-
return obj is Delta && Equals((Delta)obj);
850+
return obj is Delta delta && Equals(delta);
851851
}
852852

853853
public override int GetHashCode()
@@ -920,7 +920,7 @@ public override bool Equals(object obj)
920920
{
921921
if (ReferenceEquals(null, obj)) return false;
922922
if (ReferenceEquals(this, obj)) return true;
923-
return obj is DeltaPropagation && Equals((DeltaPropagation)obj);
923+
return obj is DeltaPropagation propagation && Equals(propagation);
924924
}
925925

926926
public override int GetHashCode()

src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() =>
324324

325325

326326
public override bool Equals(object obj) =>
327-
obj is LWWDictionary<TKey, TValue> && Equals((LWWDictionary<TKey, TValue>)obj);
327+
obj is LWWDictionary<TKey, TValue> pairs && Equals(pairs);
328328

329329

330330
public override int GetHashCode() => Underlying.GetHashCode();

src/contrib/cluster/Akka.DistributedData/LWWRegister.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public bool Equals(LWWRegister<T> other)
198198
}
199199

200200

201-
public override bool Equals(object obj) => obj is LWWRegister<T> && Equals((LWWRegister<T>)obj);
201+
public override bool Equals(object obj) => obj is LWWRegister<T> register && Equals(register);
202202

203203

204204
public override int GetHashCode()

src/contrib/cluster/Akka.DistributedData/ORMultiValueDictionary.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public IEnumerator<KeyValuePair<TKey, IImmutableSet<TValue>>> GetEnumerator() =>
282282
Underlying.Select(x => new KeyValuePair<TKey, IImmutableSet<TValue>>(x.Key, x.Value.Elements)).GetEnumerator();
283283

284284
public override bool Equals(object obj) =>
285-
obj is ORMultiValueDictionary<TKey, TValue> && Equals((ORMultiValueDictionary<TKey, TValue>)obj);
285+
obj is ORMultiValueDictionary<TKey, TValue> pairs && Equals(pairs);
286286

287287
public override int GetHashCode() => Underlying.GetHashCode();
288288
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

src/contrib/cluster/Akka.DistributedData/ORSet.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public bool Equals(ORSet<T> other)
446446
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
447447

448448

449-
public override bool Equals(object obj) => obj is ORSet<T> && Equals((ORSet<T>)obj);
449+
public override bool Equals(object obj) => obj is ORSet<T> set && Equals(set);
450450

451451

452452
public override int GetHashCode()
@@ -570,9 +570,9 @@ public override IReplicatedData Merge(IReplicatedData other)
570570
{
571571
return new DeltaGroup(ImmutableArray.Create(this, other));
572572
}
573-
else if (other is DeltaGroup)
573+
else if (other is DeltaGroup group)
574574
{
575-
var vector = ((DeltaGroup)other).Operations;
575+
var vector = group.Operations;
576576
return new DeltaGroup(vector.Add(this));
577577
}
578578
else throw new ArgumentException($"Unknown delta operation of type {other.GetType()}", nameof(other));
@@ -593,9 +593,9 @@ public override IReplicatedData Merge(IReplicatedData other)
593593
{
594594
return new DeltaGroup(ImmutableArray.Create(this, other));
595595
}
596-
else if (other is DeltaGroup)
596+
else if (other is DeltaGroup group)
597597
{
598-
var vector = ((DeltaGroup)other).Operations;
598+
var vector = group.Operations;
599599
return new DeltaGroup(vector.Add(this));
600600
}
601601
else throw new ArgumentException($"Unknown delta operation of type {other.GetType()}", nameof(other));
@@ -650,7 +650,7 @@ public override bool Equals(object obj)
650650
{
651651
if (ReferenceEquals(null, obj)) return false;
652652
if (ReferenceEquals(this, obj)) return true;
653-
return obj is DeltaGroup && Equals((DeltaGroup)obj);
653+
return obj is DeltaGroup group && Equals(group);
654654
}
655655

656656
public override int GetHashCode()

src/contrib/cluster/Akka.DistributedData/PNCounter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public bool Equals(PNCounter other)
113113
public override string ToString() => $"PNCounter({Value})";
114114

115115

116-
public override bool Equals(object obj) => obj is PNCounter && Equals((PNCounter)obj);
116+
public override bool Equals(object obj) => obj is PNCounter counter && Equals(counter);
117117

118118

119119
public override int GetHashCode() => Increments.GetHashCode() ^ Decrements.GetHashCode();

src/contrib/cluster/Akka.DistributedData/ReadAggregator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public ReadFrom(int n, TimeSpan timeout)
192192
}
193193

194194

195-
public override bool Equals(object obj) => obj is ReadFrom && Equals((ReadFrom) obj);
195+
public override bool Equals(object obj) => obj is ReadFrom from && Equals(from);
196196

197197

198198
public bool Equals(ReadFrom other)
@@ -229,7 +229,7 @@ public ReadMajority(TimeSpan timeout, int minCapacity = 0)
229229

230230
public override bool Equals(object obj)
231231
{
232-
return obj is ReadMajority && Equals((ReadMajority) obj);
232+
return obj is ReadMajority majority && Equals(majority);
233233
}
234234

235235

@@ -274,7 +274,7 @@ public ReadMajorityPlus(TimeSpan timeout, int additional, int minCapacity = 0)
274274

275275
public override bool Equals(object obj)
276276
{
277-
return obj is ReadMajorityPlus && Equals((ReadMajorityPlus)obj);
277+
return obj is ReadMajorityPlus plus && Equals(plus);
278278
}
279279

280280

@@ -314,7 +314,7 @@ public ReadAll(TimeSpan timeout)
314314

315315
public override bool Equals(object obj)
316316
{
317-
return obj is ReadAll && Equals((ReadAll) obj);
317+
return obj is ReadAll all && Equals(all);
318318
}
319319

320320

src/contrib/cluster/Akka.DistributedData/Replicator.Messages.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public GetKeysIdsResult(IImmutableSet<string> keys)
4040

4141

4242
public override bool Equals(object obj) =>
43-
obj is GetKeysIdsResult && Equals((GetKeysIdsResult)obj);
43+
obj is GetKeysIdsResult result && Equals(result);
4444

4545

4646
public bool Equals(GetKeysIdsResult other)
@@ -96,7 +96,7 @@ public bool Equals(Get other)
9696
}
9797

9898

99-
public override bool Equals(object obj) => obj is Get && Equals((Get)obj);
99+
public override bool Equals(object obj) => obj is Get get && Equals(get);
100100

101101

102102
public override int GetHashCode()
@@ -191,7 +191,7 @@ public bool Equals(GetSuccess other)
191191
}
192192

193193

194-
public override bool Equals(object obj) => obj is GetSuccess && Equals((GetSuccess)obj);
194+
public override bool Equals(object obj) => obj is GetSuccess success && Equals(success);
195195

196196

197197
public override int GetHashCode()
@@ -211,7 +211,7 @@ public override int GetHashCode()
211211

212212
public T Get<T>(IKey<T> key) where T : IReplicatedData
213213
{
214-
if (Data is T) return (T)Data;
214+
if (Data is T data) return data;
215215

216216
throw new InvalidCastException($"Response returned for key '{Key}' is of type [{Data?.GetType()}] and cannot be casted using key '{key}' to type [{typeof(T)}]");
217217
}
@@ -242,7 +242,7 @@ public bool Equals(NotFound other)
242242
}
243243

244244

245-
public override bool Equals(object obj) => obj is NotFound && Equals((NotFound)obj);
245+
public override bool Equals(object obj) => obj is NotFound found && Equals(found);
246246

247247

248248
public override string ToString() => $"NotFound({Key}{(Request == null ? "" : ", req=" + Request)})";
@@ -292,7 +292,7 @@ public bool Equals(GetFailure other)
292292
}
293293

294294

295-
public override bool Equals(object obj) => obj is GetFailure && Equals((GetFailure)obj);
295+
public override bool Equals(object obj) => obj is GetFailure failure && Equals(failure);
296296

297297

298298
public override int GetHashCode()
@@ -352,7 +352,7 @@ public bool Equals(Subscribe other)
352352
}
353353

354354

355-
public override bool Equals(object obj) => obj is Subscribe && Equals((Subscribe)obj);
355+
public override bool Equals(object obj) => obj is Subscribe subscribe && Equals(subscribe);
356356

357357

358358
public override int GetHashCode()
@@ -393,7 +393,7 @@ public bool Equals(Unsubscribe other)
393393
}
394394

395395

396-
public override bool Equals(object obj) => obj is Unsubscribe && Equals((Unsubscribe)obj);
396+
public override bool Equals(object obj) => obj is Unsubscribe unsubscribe && Equals(unsubscribe);
397397

398398

399399
public override int GetHashCode()
@@ -448,7 +448,7 @@ public T Get<T>(IKey<T> key) where T : IReplicatedData
448448
}
449449

450450

451-
public override bool Equals(object obj) => obj is Changed && Equals((Changed)obj);
451+
public override bool Equals(object obj) => obj is Changed changed && Equals(changed);
452452

453453

454454
public override int GetHashCode()
@@ -572,7 +572,7 @@ public bool Equals(UpdateSuccess other)
572572
}
573573

574574

575-
public override bool Equals(object obj) => obj is UpdateSuccess && Equals((UpdateSuccess)obj);
575+
public override bool Equals(object obj) => obj is UpdateSuccess success && Equals(success);
576576

577577

578578
public override int GetHashCode()
@@ -631,7 +631,7 @@ public bool Equals(UpdateTimeout other)
631631
}
632632

633633

634-
public override bool Equals(object obj) => obj is UpdateTimeout && Equals((UpdateTimeout)obj);
634+
public override bool Equals(object obj) => obj is UpdateTimeout timeout && Equals(timeout);
635635

636636

637637
public override string ToString() => $"UpdateTimeout({Key}{(Request == null ? "" : ", req=" + Request)})";
@@ -738,7 +738,7 @@ public override bool Equals(object obj)
738738
{
739739
if (ReferenceEquals(null, obj)) return false;
740740
if (ReferenceEquals(this, obj)) return true;
741-
return obj is StoreFailure && Equals((StoreFailure)obj);
741+
return obj is StoreFailure failure && Equals(failure);
742742
}
743743

744744

@@ -779,7 +779,7 @@ public bool Equals(Delete other)
779779
}
780780

781781

782-
public override bool Equals(object obj) => obj is Delete && Equals((Delete)obj);
782+
public override bool Equals(object obj) => obj is Delete delete && Equals(delete);
783783

784784

785785
public override int GetHashCode()
@@ -853,7 +853,7 @@ public bool Equals(DeleteSuccess other)
853853
}
854854

855855

856-
public override bool Equals(object obj) => obj is DeleteSuccess && Equals((DeleteSuccess)obj);
856+
public override bool Equals(object obj) => obj is DeleteSuccess success && Equals(success);
857857

858858

859859
public override int GetHashCode() => Key.GetHashCode();
@@ -884,7 +884,7 @@ public bool Equals(ReplicationDeleteFailure other)
884884
}
885885

886886

887-
public override bool Equals(object obj) => obj is ReplicationDeleteFailure && Equals((ReplicationDeleteFailure)obj);
887+
public override bool Equals(object obj) => obj is ReplicationDeleteFailure failure && Equals(failure);
888888

889889

890890
public override int GetHashCode() => Key.GetHashCode();
@@ -920,7 +920,7 @@ public bool Equals(DataDeleted other)
920920
}
921921

922922

923-
public override bool Equals(object obj) => obj is DataDeleted && Equals((DataDeleted)obj);
923+
public override bool Equals(object obj) => obj is DataDeleted deleted && Equals(deleted);
924924

925925

926926
public override int GetHashCode() => Key.GetHashCode();
@@ -967,7 +967,7 @@ public ReplicaCount(int n)
967967
public bool Equals(ReplicaCount other) => other != null && N == other.N;
968968

969969

970-
public override bool Equals(object obj) => obj is ReplicaCount && Equals((ReplicaCount)obj);
970+
public override bool Equals(object obj) => obj is ReplicaCount count && Equals(count);
971971

972972

973973
public override int GetHashCode() => N.GetHashCode();

src/contrib/persistence/Akka.Persistence.Sql.Common/Snapshot/QueryExecutor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ protected virtual void SetManifestParameters(object snapshot, DbCommand command)
429429
var serializer = Serialization.FindSerializerForType(snapshotType);
430430

431431
string manifest = "";
432-
if (serializer is SerializerWithStringManifest)
432+
if (serializer is SerializerWithStringManifest stringManifest)
433433
{
434-
manifest = ((SerializerWithStringManifest)serializer).Manifest(snapshot);
434+
manifest = stringManifest.Manifest(snapshot);
435435
}
436436
else
437437
{

0 commit comments

Comments
 (0)