Equal overrides
This commit is contained in:
parent
60c1ece41d
commit
90f804c7c6
@ -69,6 +69,21 @@ public abstract class Device : IDisposable
|
||||
$"DurationRange: {DurationRange}\n\r";
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Device d && Equals(d);
|
||||
}
|
||||
|
||||
protected bool Equals(Device other)
|
||||
{
|
||||
return IntensityRange.Equals(other.IntensityRange) && DurationRange.Equals(other.DurationRange) && ApiType == other.ApiType;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(IntensityRange, DurationRange, (int)ApiType);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_workQueue = false;
|
||||
|
@ -18,7 +18,22 @@ public abstract class OpenShockDevice : Device
|
||||
this.Endpoint = endpoint;
|
||||
this.ApiKey = apiKey;
|
||||
}
|
||||
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is OpenShockDevice osd && Equals(osd);
|
||||
}
|
||||
|
||||
private bool Equals(OpenShockDevice other)
|
||||
{
|
||||
return base.Equals(other) && Endpoint == other.Endpoint && ApiKey == other.ApiKey;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Endpoint, ApiKey);
|
||||
}
|
||||
|
||||
public List<OpenShockShocker> GetShockers()
|
||||
{
|
||||
List<OpenShockShocker> shockers = new();
|
||||
|
@ -6,4 +6,9 @@ public class DurationRange : RandomIntegerRange
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is IntensityRange && base.Equals(obj);
|
||||
}
|
||||
}
|
@ -6,4 +6,9 @@ public class IntensityRange : RandomIntegerRange
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is IntensityRange && base.Equals(obj);
|
||||
}
|
||||
}
|
@ -24,4 +24,11 @@ public abstract class RandomIntegerRange
|
||||
{
|
||||
return $"Min: {Min} Max: {Max}";
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is RandomIntegerRange rir &&
|
||||
this.Min == rir.Min &&
|
||||
this.Max == rir.Max;
|
||||
}
|
||||
}
|
@ -29,4 +29,20 @@ public struct OpenShockShocker : IShocker
|
||||
$"Created On: {createdOn}\n" +
|
||||
$"Paused: {isPaused}\n\r";
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is OpenShockShocker oss && Equals(oss);
|
||||
|
||||
}
|
||||
|
||||
private bool Equals(OpenShockShocker other)
|
||||
{
|
||||
return id == other.id && rfId == other.rfId && model == other.model && createdOn.Equals(other.createdOn);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(id, rfId, (int)model, createdOn);
|
||||
}
|
||||
}
|
@ -5,4 +5,19 @@ namespace CShocker.Shockers;
|
||||
public struct PiShockShocker : IShocker
|
||||
{
|
||||
public string Code;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is PiShockShocker pss && Equals(pss);
|
||||
}
|
||||
|
||||
private bool Equals(PiShockShocker other)
|
||||
{
|
||||
return Code == other.Code;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Code.GetHashCode();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user