Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Ical.Net/CalendarComponents/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@
}
else
{
var dt = Trigger.DateTime.Copy();
occurrences.Add(new AlarmOccurrence(this, dt, rc));
var dt = Trigger?.DateTime?.Copy();

Check warning on line 128 in Ical.Net/CalendarComponents/Alarm.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/Alarm.cs#L128

Added line #L128 was not covered by tests
if (dt != null)
{
occurrences.Add(new AlarmOccurrence(this, dt, rc));

Check warning on line 131 in Ical.Net/CalendarComponents/Alarm.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/Alarm.cs#L131

Added line #L131 was not covered by tests
}
}

// If a REPEAT and DURATION value were specified,
Expand All @@ -150,8 +153,7 @@
var results = new List<AlarmOccurrence>();

// Evaluate the alarms to determine the recurrences
var rc = Parent as RecurringComponent;
if (rc == null)
if (Parent is not RecurringComponent rc)
{
return results;
}
Expand Down
5 changes: 3 additions & 2 deletions Ical.Net/DataTypes/EncodableDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
// Licensed under the MIT license.
//

#nullable enable
namespace Ical.Net.DataTypes;

/// <summary>
/// An abstract class from which all iCalendar data types inherit.
/// </summary>
public class EncodableDataType : CalendarDataType, IEncodableDataType
{
public virtual string Encoding
public virtual string? Encoding
{
get => Parameters.Get("ENCODING");
set => Parameters.Set("ENCODING", value);
}
}
}
7 changes: 4 additions & 3 deletions Ical.Net/DataTypes/FreeBusyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license.
//

#nullable enable
namespace Ical.Net.DataTypes;

public class FreeBusyEntry : Period
Expand All @@ -16,8 +17,8 @@ public FreeBusyEntry()

public FreeBusyEntry(Period period, FreeBusyStatus status)
{
//Sets the status associated with a given period, which requires copying the period values
//Probably the Period object should just have a FreeBusyStatus directly?
// Sets the status associated with a given period, which requires copying the period values
// Probably the Period object should just have a FreeBusyStatus directly?
CopyFrom(period);
Status = status;
}
Expand All @@ -32,4 +33,4 @@ public override void CopyFrom(ICopyable obj)
Status = fb.Status;
}
}
}
}
5 changes: 3 additions & 2 deletions Ical.Net/DataTypes/GeographicLocation.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.Diagnostics;
using Ical.Net.CalendarComponents;
using Ical.Net.Serialization.DataTypes;
Expand Down Expand Up @@ -52,7 +53,7 @@ public override void CopyFrom(ICopyable obj)

protected bool Equals(GeographicLocation other) => Latitude.Equals(other.Latitude) && Longitude.Equals(other.Longitude);

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 @@ -66,4 +67,4 @@ public override int GetHashCode()
return (Latitude.GetHashCode() * 397) ^ Longitude.GetHashCode();
}
}
}
}
25 changes: 6 additions & 19 deletions Ical.Net/DataTypes/Occurrence.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 Ical.Net.CalendarComponents;

Expand All @@ -27,13 +28,13 @@ public Occurrence(IRecurrable recurrable, Period period)

public bool Equals(Occurrence other) => Equals(Period, other.Period) && Equals(Source, other.Source);

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is Occurrence && Equals((Occurrence) obj);
return obj is Occurrence occurrence && Equals(occurrence);
}

public override int GetHashCode()
Expand All @@ -44,21 +45,7 @@ public override int GetHashCode()
}
}

public override string ToString()
{
var s = "Occurrence";
if (Source != null)
{
s = Source.GetType().Name + " ";
}

if (Period != null)
{
s += "(" + Period.StartTime + ")";
}

return s;
}
public override string ToString() => $"Occurrence {Source.GetType().Name} ({Period.StartTime})";

public int CompareTo(Occurrence other) => Period.CompareTo(other.Period);
}
public int CompareTo(Occurrence? other) => Period.CompareTo(other?.Period);
}
27 changes: 14 additions & 13 deletions Ical.Net/DataTypes/RequestStatus.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.IO;
using Ical.Net.Serialization.DataTypes;

Expand All @@ -13,23 +14,23 @@
/// </summary>
public class RequestStatus : EncodableDataType
{
private string _mDescription;
private string _mExtraData;
private StatusCode _mStatusCode;
private string? _mDescription;
private string? _mExtraData;
private StatusCode? _mStatusCode;

public virtual string Description
public virtual string? Description
{
get => _mDescription;
set => _mDescription = value;
}

public virtual string ExtraData
public virtual string? ExtraData
{
get => _mExtraData;
set => _mExtraData = value;
}

public virtual StatusCode StatusCode
public virtual StatusCode? StatusCode
{
get => _mStatusCode;
set => _mStatusCode = value;
Expand All @@ -40,7 +41,10 @@
public RequestStatus(string value) : this()
{
var serializer = new RequestStatusSerializer();
CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
if (serializer.Deserialize(new StringReader(value)) is ICopyable deserializedObject)
{
CopyFrom(deserializedObject);

Check warning on line 46 in Ical.Net/DataTypes/RequestStatus.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/RequestStatus.cs#L46

Added line #L46 was not covered by tests
}
}

/// <inheritdoc/>
Expand All @@ -52,10 +56,7 @@
return;
}

if (rs.StatusCode != null)
{
StatusCode = rs.StatusCode;
}
StatusCode = rs.StatusCode;

Check warning on line 59 in Ical.Net/DataTypes/RequestStatus.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/RequestStatus.cs#L59

Added line #L59 was not covered by tests
Description = rs.Description;
ExtraData = rs.ExtraData;
}
Expand All @@ -69,7 +70,7 @@
protected bool Equals(RequestStatus other) => string.Equals(_mDescription, other._mDescription) && string.Equals(_mExtraData, other._mExtraData) &&
Equals(_mStatusCode, other._mStatusCode);

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
{
Expand All @@ -96,4 +97,4 @@
return hashCode;
}
}
}
}
16 changes: 12 additions & 4 deletions Ical.Net/DataTypes/StatusCode.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.IO;
using System.Linq;
using Ical.Net.Serialization.DataTypes;
Expand Down Expand Up @@ -37,7 +38,10 @@
? Parts[2]
: 0;

public StatusCode() { }
public StatusCode()
{
Parts = System.Array.Empty<int>();
}

public StatusCode(int[] parts)
{
Expand All @@ -47,7 +51,11 @@
public StatusCode(string value) : this()
{
var serializer = new StatusCodeSerializer();
CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
var deserialized = serializer.Deserialize(new StringReader(value)) as ICopyable;

Check warning on line 54 in Ical.Net/DataTypes/StatusCode.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/StatusCode.cs#L54

Added line #L54 was not covered by tests
if (deserialized != null)
{
CopyFrom(deserialized);

Check warning on line 57 in Ical.Net/DataTypes/StatusCode.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/StatusCode.cs#L57

Added line #L57 was not covered by tests
}
}

/// <inheritdoc/>
Expand All @@ -64,7 +72,7 @@

protected bool Equals(StatusCode other) => Parts.SequenceEqual(other.Parts);

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
{
Expand All @@ -82,4 +90,4 @@
}

public override int GetHashCode() => CollectionHelpers.GetHashCode(Parts);
}
}
17 changes: 8 additions & 9 deletions Ical.Net/DataTypes/Trigger.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.IO;
using Ical.Net.Serialization.DataTypes;
Expand All @@ -15,11 +16,11 @@
/// </summary>
public class Trigger : EncodableDataType
{
private CalDateTime _mDateTime;
private CalDateTime? _mDateTime;
private Duration? _mDuration;
private string _mRelated = TriggerRelation.Start;

public virtual CalDateTime DateTime
public virtual CalDateTime? DateTime
{
get => _mDateTime;
set
Expand All @@ -30,9 +31,6 @@
return;
}

// NOTE: this, along with the "Duration" setter, fixes the bug tested in
// TODO11(), as well as this thread: https://sourceforge.net/forum/forum.php?thread_id=1926742&forum_id=656447

// DateTime and Duration are mutually exclusive
Duration = null;

Expand All @@ -52,8 +50,6 @@
_mDuration = value;
if (_mDuration != null)
{
// NOTE: see above.

// DateTime and Duration are mutually exclusive
DateTime = null;
}
Expand All @@ -78,7 +74,10 @@
public Trigger(string value) : this()
{
var serializer = new TriggerSerializer();
CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
if (serializer.Deserialize(new StringReader(value)) is ICopyable deserializedObject)
{
CopyFrom(deserializedObject);

Check warning on line 79 in Ical.Net/DataTypes/Trigger.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/Trigger.cs#L79

Added line #L79 was not covered by tests
}
}

/// <inheritdoc/>
Expand All @@ -97,7 +96,7 @@

protected bool Equals(Trigger other) => Equals(_mDateTime, other._mDateTime) && _mDuration.Equals(other._mDuration) && _mRelated == other._mRelated;

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
{
Expand Down
5 changes: 3 additions & 2 deletions Ical.Net/DataTypes/UTCOffset.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 Ical.Net.Serialization.DataTypes;

Expand Down Expand Up @@ -45,7 +46,7 @@ public UtcOffset(TimeSpan ts)

protected bool Equals(UtcOffset other) => Offset == other.Offset;

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
{
Expand Down Expand Up @@ -76,4 +77,4 @@ public override void CopyFrom(ICopyable obj)
Offset = o.Offset;
}
}
}
}
Loading
Loading