-
Notifications
You must be signed in to change notification settings - Fork 137
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
Implement equality for 'ContrabSchedule' #56
Comments
I'll think about this but meanwhile…
The NCrontab/NCrontab/CrontabSchedule.cs Lines 376 to 397 in b6659e4
It can be used today as a good basis for equality comparison via an sealed class EqualityComparer<CrontabSchedule> : IEqualityComparer<CrontabSchedule>
{
public bool Equals(CrontabSchedule x, CrontabSchedule y) =>
x?.ToString() == y?.ToString();
public int GetHashCode(CrontabSchedule obj) =>
obj.ToString().GetHashCode();
} Usage would then be: var comparer = new EqualityComparer<CrontabSchedule>();
var schedule1 = CrontabSchedule.Parse("0-59 * * * Mon-Fri/2");
var schedule2 = CrontabSchedule.Parse("* * * * Fri,Mon,Wed");
var schedule3 = CrontabSchedule.Parse("* * * * *");
Console.WriteLine(comparer.Equals(schedule1, schedule2)); // True
Console.WriteLine(comparer.Equals(schedule1, schedule3)); // False
Console.WriteLine(comparer.Equals(schedule2, schedule3)); // False Note how |
There is currently no way to check a
ContrabSchedule
object for equality against another schedule. It's also not possible to properly implement a customEqualityComparer
from the outside since the fields that store the data inside the schedule are all private.This could be fixed by implementing
IEquatable<ContrabSchedule>
on the model.The text was updated successfully, but these errors were encountered: