Skip to content
38 changes: 19 additions & 19 deletions Ical.Net/DataTypes/Attendee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license.
//

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -12,9 +13,9 @@ namespace Ical.Net.DataTypes;

public class Attendee : EncodableDataType
{
private Uri _sentBy;
private Uri? _sentBy;
/// <summary> SENT-BY, to indicate who is acting on behalf of the ATTENDEE </summary>
public virtual Uri SentBy
public virtual Uri? SentBy
{
get
{
Expand All @@ -38,7 +39,7 @@ public virtual Uri SentBy
}
}

private string _commonName;
private string? _commonName;
/// <summary> CN: to show the common or displayable name associated with the calendar address </summary>
public virtual string CommonName
{
Expand All @@ -61,9 +62,9 @@ public virtual string CommonName
}
}

private Uri _directoryEntry;
private Uri? _directoryEntry;
/// <summary> DIR, to indicate the URI that points to the directory information corresponding to the attendee </summary>
public virtual Uri DirectoryEntry
public virtual Uri? DirectoryEntry
{
get
{
Expand All @@ -87,7 +88,7 @@ public virtual Uri DirectoryEntry
}
}

private string _type;
private string? _type;
/// <summary> CUTYPE: the type of calendar user </summary>
public virtual string Type
{
Expand All @@ -111,7 +112,7 @@ public virtual string Type
}
}

private List<string> _members;
private List<string>? _members;
/// <summary> MEMBER: the groups the user belongs to </summary>
public virtual IList<string> Members
{
Expand All @@ -123,7 +124,7 @@ public virtual IList<string> Members
}
}

private string _role;
private string? _role;
/// <summary> ROLE: the intended role the attendee will have </summary>
public virtual string Role
{
Expand All @@ -146,7 +147,7 @@ public virtual string Role
}
}

private string _participationStatus;
private string? _participationStatus;
public virtual string ParticipationStatus
{
get
Expand Down Expand Up @@ -179,9 +180,8 @@ public virtual bool Rsvp
return _rsvp.Value;
}

bool val;
var rsvp = Parameters.Get("RSVP");
if (rsvp != null && bool.TryParse(rsvp, out val))
if (rsvp != null && bool.TryParse(rsvp, out var val))
{
_rsvp = val;
return _rsvp.Value;
Expand All @@ -196,9 +196,9 @@ public virtual bool Rsvp
}
}

private List<string> _delegatedTo;
private List<string>? _delegatedTo;
/// <summary> DELEGATED-TO, to indicate the calendar users that the original request was delegated to </summary>
public virtual IList<string> DelegatedTo
public virtual IList<string>? DelegatedTo
{
get => _delegatedTo ?? (_delegatedTo = new List<string>(Parameters.GetMany("DELEGATED-TO")));
set
Expand All @@ -212,7 +212,7 @@ public virtual IList<string> DelegatedTo
}
}

private List<string> _delegatedFrom;
private List<string>? _delegatedFrom;
/// <summary> DELEGATED-FROM, to indicate whom the request was delegated from </summary>
public virtual IList<string> DelegatedFrom
{
Expand All @@ -229,7 +229,7 @@ public virtual IList<string> DelegatedFrom
}

/// <summary> Uri associated with the attendee, typically an email address </summary>
public virtual Uri Value { get; set; }
public virtual Uri? Value { get; set; }

public Attendee() { }

Expand Down Expand Up @@ -276,10 +276,10 @@ protected bool Equals(Attendee other) => Equals(SentBy, other.SentBy)
&& Rsvp == other.Rsvp
&& Equals(Value, other.Value)
&& Members.SequenceEqual(other.Members)
&& DelegatedTo.SequenceEqual(other.DelegatedTo)
&& DelegatedFrom.SequenceEqual(other.DelegatedFrom);
&& (DelegatedTo?.SequenceEqual(other.DelegatedTo ?? Enumerable.Empty<string>()) ?? other.DelegatedTo == null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparison is not commutative this way. I.e. if one is null and the other is empty, then the comparison is not symmetrical. Not sure though, whether an empty sequence should equal null. Usually they're considered different.

&& (DelegatedFrom?.SequenceEqual(other.DelegatedFrom ?? Enumerable.Empty<string>()) ?? other.DelegatedFrom == null);

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
Expand All @@ -305,4 +305,4 @@ public override int GetHashCode()
return hashCode;
}
}
}
}