Skip to content

remove some casts #6710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is SendToOneSubscriber && Equals((SendToOneSubscriber)obj);
return obj is SendToOneSubscriber subscriber && Equals(subscriber);
}

public override int GetHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is DurableDataEnvelope && Equals((DurableDataEnvelope) obj);
return obj is DurableDataEnvelope envelope && Equals(envelope);
}
}
}
4 changes: 2 additions & 2 deletions src/contrib/cluster/Akka.DistributedData/Flag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public bool Equals(Flag other)
}


public override bool Equals(object obj) => obj is Flag && Equals((Flag) obj);
public override bool Equals(object obj) => obj is Flag flag && Equals(flag);

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/contrib/cluster/Akka.DistributedData/GSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public bool Equals(GSet<T> other)
public IEnumerator<T> GetEnumerator() => Elements.GetEnumerator();


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


public override int GetHashCode()
Expand Down
16 changes: 8 additions & 8 deletions src/contrib/cluster/Akka.DistributedData/Internal/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public bool Equals(Write other)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Write && Equals((Write)obj);
public override bool Equals(object obj) => obj is Write write && Equals(write);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down Expand Up @@ -245,7 +245,7 @@ public bool Equals(Read other)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Read && Equals((Read)obj);
public override bool Equals(object obj) => obj is Read read && Equals(read);

/// <inheritdoc/>
public override int GetHashCode() => Key?.GetHashCode() ?? 0;
Expand Down Expand Up @@ -284,7 +284,7 @@ public bool Equals(ReadResult other)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is ReadResult && Equals((ReadResult)obj);
public override bool Equals(object obj) => obj is ReadResult result && Equals(result);

/// <inheritdoc/>
public override int GetHashCode() => Envelope?.GetHashCode() ?? 0;
Expand Down Expand Up @@ -329,7 +329,7 @@ public bool Equals(ReadRepair other)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is ReadRepair && Equals((ReadRepair)obj);
public override bool Equals(object obj) => obj is ReadRepair repair && Equals(repair);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down Expand Up @@ -715,7 +715,7 @@ public bool Equals(Status other)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Status && Equals((Status)obj);
public override bool Equals(object obj) => obj is Status status && Equals(status);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down Expand Up @@ -795,7 +795,7 @@ public bool Equals(Gossip other)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Gossip && Equals((Gossip)obj);
public override bool Equals(object obj) => obj is Gossip gossip && Equals(gossip);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down Expand Up @@ -847,7 +847,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is Delta && Equals((Delta)obj);
return obj is Delta delta && Equals(delta);
}

public override int GetHashCode()
Expand Down Expand Up @@ -920,7 +920,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is DeltaPropagation && Equals((DeltaPropagation)obj);
return obj is DeltaPropagation propagation && Equals(propagation);
}

public override int GetHashCode()
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() =>


public override bool Equals(object obj) =>
obj is LWWDictionary<TKey, TValue> && Equals((LWWDictionary<TKey, TValue>)obj);
obj is LWWDictionary<TKey, TValue> pairs && Equals(pairs);


public override int GetHashCode() => Underlying.GetHashCode();
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/cluster/Akka.DistributedData/LWWRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public bool Equals(LWWRegister<T> other)
}


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


public override int GetHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public IEnumerator<KeyValuePair<TKey, IImmutableSet<TValue>>> GetEnumerator() =>
Underlying.Select(x => new KeyValuePair<TKey, IImmutableSet<TValue>>(x.Key, x.Value.Elements)).GetEnumerator();

public override bool Equals(object obj) =>
obj is ORMultiValueDictionary<TKey, TValue> && Equals((ORMultiValueDictionary<TKey, TValue>)obj);
obj is ORMultiValueDictionary<TKey, TValue> pairs && Equals(pairs);

public override int GetHashCode() => Underlying.GetHashCode();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
Expand Down
12 changes: 6 additions & 6 deletions src/contrib/cluster/Akka.DistributedData/ORSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public bool Equals(ORSet<T> other)
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();


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


public override int GetHashCode()
Expand Down Expand Up @@ -570,9 +570,9 @@ public override IReplicatedData Merge(IReplicatedData other)
{
return new DeltaGroup(ImmutableArray.Create(this, other));
}
else if (other is DeltaGroup)
else if (other is DeltaGroup group)
{
var vector = ((DeltaGroup)other).Operations;
var vector = group.Operations;
return new DeltaGroup(vector.Add(this));
}
else throw new ArgumentException($"Unknown delta operation of type {other.GetType()}", nameof(other));
Expand All @@ -593,9 +593,9 @@ public override IReplicatedData Merge(IReplicatedData other)
{
return new DeltaGroup(ImmutableArray.Create(this, other));
}
else if (other is DeltaGroup)
else if (other is DeltaGroup group)
{
var vector = ((DeltaGroup)other).Operations;
var vector = group.Operations;
return new DeltaGroup(vector.Add(this));
}
else throw new ArgumentException($"Unknown delta operation of type {other.GetType()}", nameof(other));
Expand Down Expand Up @@ -650,7 +650,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is DeltaGroup && Equals((DeltaGroup)obj);
return obj is DeltaGroup group && Equals(group);
}

public override int GetHashCode()
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/cluster/Akka.DistributedData/PNCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public bool Equals(PNCounter other)
public override string ToString() => $"PNCounter({Value})";


public override bool Equals(object obj) => obj is PNCounter && Equals((PNCounter)obj);
public override bool Equals(object obj) => obj is PNCounter counter && Equals(counter);


public override int GetHashCode() => Increments.GetHashCode() ^ Decrements.GetHashCode();
Expand Down
8 changes: 4 additions & 4 deletions src/contrib/cluster/Akka.DistributedData/ReadAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public ReadFrom(int n, TimeSpan timeout)
}


public override bool Equals(object obj) => obj is ReadFrom && Equals((ReadFrom) obj);
public override bool Equals(object obj) => obj is ReadFrom from && Equals(from);


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

public override bool Equals(object obj)
{
return obj is ReadMajority && Equals((ReadMajority) obj);
return obj is ReadMajority majority && Equals(majority);
}


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

public override bool Equals(object obj)
{
return obj is ReadMajorityPlus && Equals((ReadMajorityPlus)obj);
return obj is ReadMajorityPlus plus && Equals(plus);
}


Expand Down Expand Up @@ -314,7 +314,7 @@ public ReadAll(TimeSpan timeout)

public override bool Equals(object obj)
{
return obj is ReadAll && Equals((ReadAll) obj);
return obj is ReadAll all && Equals(all);
}


Expand Down
34 changes: 17 additions & 17 deletions src/contrib/cluster/Akka.DistributedData/Replicator.Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public GetKeysIdsResult(IImmutableSet<string> keys)


public override bool Equals(object obj) =>
obj is GetKeysIdsResult && Equals((GetKeysIdsResult)obj);
obj is GetKeysIdsResult result && Equals(result);


public bool Equals(GetKeysIdsResult other)
Expand Down Expand Up @@ -96,7 +96,7 @@ public bool Equals(Get other)
}


public override bool Equals(object obj) => obj is Get && Equals((Get)obj);
public override bool Equals(object obj) => obj is Get get && Equals(get);


public override int GetHashCode()
Expand Down Expand Up @@ -191,7 +191,7 @@ public bool Equals(GetSuccess other)
}


public override bool Equals(object obj) => obj is GetSuccess && Equals((GetSuccess)obj);
public override bool Equals(object obj) => obj is GetSuccess success && Equals(success);


public override int GetHashCode()
Expand All @@ -211,7 +211,7 @@ public override int GetHashCode()

public T Get<T>(IKey<T> key) where T : IReplicatedData
{
if (Data is T) return (T)Data;
if (Data is T data) return data;

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


public override bool Equals(object obj) => obj is NotFound && Equals((NotFound)obj);
public override bool Equals(object obj) => obj is NotFound found && Equals(found);


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


public override bool Equals(object obj) => obj is GetFailure && Equals((GetFailure)obj);
public override bool Equals(object obj) => obj is GetFailure failure && Equals(failure);


public override int GetHashCode()
Expand Down Expand Up @@ -352,7 +352,7 @@ public bool Equals(Subscribe other)
}


public override bool Equals(object obj) => obj is Subscribe && Equals((Subscribe)obj);
public override bool Equals(object obj) => obj is Subscribe subscribe && Equals(subscribe);


public override int GetHashCode()
Expand Down Expand Up @@ -393,7 +393,7 @@ public bool Equals(Unsubscribe other)
}


public override bool Equals(object obj) => obj is Unsubscribe && Equals((Unsubscribe)obj);
public override bool Equals(object obj) => obj is Unsubscribe unsubscribe && Equals(unsubscribe);


public override int GetHashCode()
Expand Down Expand Up @@ -448,7 +448,7 @@ public T Get<T>(IKey<T> key) where T : IReplicatedData
}


public override bool Equals(object obj) => obj is Changed && Equals((Changed)obj);
public override bool Equals(object obj) => obj is Changed changed && Equals(changed);


public override int GetHashCode()
Expand Down Expand Up @@ -572,7 +572,7 @@ public bool Equals(UpdateSuccess other)
}


public override bool Equals(object obj) => obj is UpdateSuccess && Equals((UpdateSuccess)obj);
public override bool Equals(object obj) => obj is UpdateSuccess success && Equals(success);


public override int GetHashCode()
Expand Down Expand Up @@ -631,7 +631,7 @@ public bool Equals(UpdateTimeout other)
}


public override bool Equals(object obj) => obj is UpdateTimeout && Equals((UpdateTimeout)obj);
public override bool Equals(object obj) => obj is UpdateTimeout timeout && Equals(timeout);


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


Expand Down Expand Up @@ -779,7 +779,7 @@ public bool Equals(Delete other)
}


public override bool Equals(object obj) => obj is Delete && Equals((Delete)obj);
public override bool Equals(object obj) => obj is Delete delete && Equals(delete);


public override int GetHashCode()
Expand Down Expand Up @@ -853,7 +853,7 @@ public bool Equals(DeleteSuccess other)
}


public override bool Equals(object obj) => obj is DeleteSuccess && Equals((DeleteSuccess)obj);
public override bool Equals(object obj) => obj is DeleteSuccess success && Equals(success);


public override int GetHashCode() => Key.GetHashCode();
Expand Down Expand Up @@ -884,7 +884,7 @@ public bool Equals(ReplicationDeleteFailure other)
}


public override bool Equals(object obj) => obj is ReplicationDeleteFailure && Equals((ReplicationDeleteFailure)obj);
public override bool Equals(object obj) => obj is ReplicationDeleteFailure failure && Equals(failure);


public override int GetHashCode() => Key.GetHashCode();
Expand Down Expand Up @@ -920,7 +920,7 @@ public bool Equals(DataDeleted other)
}


public override bool Equals(object obj) => obj is DataDeleted && Equals((DataDeleted)obj);
public override bool Equals(object obj) => obj is DataDeleted deleted && Equals(deleted);


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


public override bool Equals(object obj) => obj is ReplicaCount && Equals((ReplicaCount)obj);
public override bool Equals(object obj) => obj is ReplicaCount count && Equals(count);


public override int GetHashCode() => N.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ protected virtual void SetManifestParameters(object snapshot, DbCommand command)
var serializer = Serialization.FindSerializerForType(snapshotType);

string manifest = "";
if (serializer is SerializerWithStringManifest)
if (serializer is SerializerWithStringManifest stringManifest)
{
manifest = ((SerializerWithStringManifest)serializer).Manifest(snapshot);
manifest = stringManifest.Manifest(snapshot);
}
else
{
Expand Down
Loading