Skip to content
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

CalDateTime equality operators handle null-values incorrectly. #372

Closed
minichma opened this issue Mar 30, 2018 · 2 comments
Closed

CalDateTime equality operators handle null-values incorrectly. #372

minichma opened this issue Mar 30, 2018 · 2 comments

Comments

@minichma
Copy link

minichma commented Mar 30, 2018

CalDateTime.operator == and CalDateTime.operator != fail when comparing against null. This implies, that natural expressions like ((x == null) || (x <= y)) fail. This certainly violates the intended contract for == and !=. It probably should be implemented similar to:

public static bool operator ==(CalDateTime left, IDateTime right) => 
    (ReferenceEquals(left, null) || ReferenceEquals(right, null))
    ? ReferenceEquals(left, right):
    left.Equals(right);

public static bool operator !=(CalDateTime left, IDateTime right) =>
    (ReferenceEquals(left, null) || ReferenceEquals(right, null))
    ? !ReferenceEquals(left, right) :
    !left.Equals(right);

Other comparison operators should probably handle null values gracefully too. Here is, how Nullable<T> does it:

When you perform comparisons with nullable types, if the value of one of the nullable types is null and the other is not, all comparisons evaluate to false except for != (not equal).

@rianjs
Copy link
Owner

rianjs commented May 27, 2018

Looks reasonable. I’ll merge a stylistically tweaked version of this this week.

@rianjs
Copy link
Owner

rianjs commented May 29, 2018

Available in nuget version 4.1.5:
https://www.nuget.org/packages/Ical.Net/4.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants