Equal overrides

This commit is contained in:
2024-01-29 17:05:13 +01:00
parent 60c1ece41d
commit 90f804c7c6
7 changed files with 79 additions and 1 deletions

View File

@ -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;

View File

@ -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();