Skip to content

Commit 3c6fec7

Browse files
authored
Enable NRT for EncodableDataType, FreeBusyEntry, GeographicLocation, Occurrence, RequestStatus, StatusCode, Trigger, UTCOffset, WeekDay (#763)
* Enable NRT for `EncodableDataType` * Enable NRT for `FreeBusyEntry` * Enable NRT for `GeographicLocation` * Enable NRT for `DataTypes.Occurrence` * Enable NRT for `RequestStatus` * Enable NRT for `StatusCode` * Enable NRT for `Trigger` * Enable NRT for `UTCOffset` * Enable NRT for `DataTypes.WeekDay`
1 parent e44021e commit 3c6fec7

File tree

10 files changed

+74
-71
lines changed

10 files changed

+74
-71
lines changed

Ical.Net/CalendarComponents/Alarm.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ public virtual IList<AlarmOccurrence> GetOccurrences(IRecurringComponent rc, Cal
125125
}
126126
else
127127
{
128-
var dt = Trigger.DateTime.Copy();
129-
occurrences.Add(new AlarmOccurrence(this, dt, rc));
128+
var dt = Trigger?.DateTime?.Copy();
129+
if (dt != null)
130+
{
131+
occurrences.Add(new AlarmOccurrence(this, dt, rc));
132+
}
130133
}
131134

132135
// If a REPEAT and DURATION value were specified,
@@ -150,8 +153,7 @@ public virtual IList<AlarmOccurrence> Poll(CalDateTime? start, CalDateTime? end,
150153
var results = new List<AlarmOccurrence>();
151154

152155
// Evaluate the alarms to determine the recurrences
153-
var rc = Parent as RecurringComponent;
154-
if (rc == null)
156+
if (Parent is not RecurringComponent rc)
155157
{
156158
return results;
157159
}

Ical.Net/DataTypes/EncodableDataType.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
namespace Ical.Net.DataTypes;
78

89
/// <summary>
910
/// An abstract class from which all iCalendar data types inherit.
1011
/// </summary>
1112
public class EncodableDataType : CalendarDataType, IEncodableDataType
1213
{
13-
public virtual string Encoding
14+
public virtual string? Encoding
1415
{
1516
get => Parameters.Get("ENCODING");
1617
set => Parameters.Set("ENCODING", value);
1718
}
18-
}
19+
}

Ical.Net/DataTypes/FreeBusyEntry.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
namespace Ical.Net.DataTypes;
78

89
public class FreeBusyEntry : Period
@@ -16,8 +17,8 @@ public FreeBusyEntry()
1617

1718
public FreeBusyEntry(Period period, FreeBusyStatus status)
1819
{
19-
//Sets the status associated with a given period, which requires copying the period values
20-
//Probably the Period object should just have a FreeBusyStatus directly?
20+
// Sets the status associated with a given period, which requires copying the period values
21+
// Probably the Period object should just have a FreeBusyStatus directly?
2122
CopyFrom(period);
2223
Status = status;
2324
}
@@ -32,4 +33,4 @@ public override void CopyFrom(ICopyable obj)
3233
Status = fb.Status;
3334
}
3435
}
35-
}
36+
}

Ical.Net/DataTypes/GeographicLocation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
using System.Diagnostics;
78
using Ical.Net.CalendarComponents;
89
using Ical.Net.Serialization.DataTypes;
@@ -52,7 +53,7 @@ public override void CopyFrom(ICopyable obj)
5253

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

55-
public override bool Equals(object obj)
56+
public override bool Equals(object? obj)
5657
{
5758
if (ReferenceEquals(null, obj)) return false;
5859
if (ReferenceEquals(this, obj)) return true;
@@ -66,4 +67,4 @@ public override int GetHashCode()
6667
return (Latitude.GetHashCode() * 397) ^ Longitude.GetHashCode();
6768
}
6869
}
69-
}
70+
}

Ical.Net/DataTypes/Occurrence.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
using System;
78
using Ical.Net.CalendarComponents;
89

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

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

30-
public override bool Equals(object obj)
31+
public override bool Equals(object? obj)
3132
{
3233
if (ReferenceEquals(null, obj))
3334
{
3435
return false;
3536
}
36-
return obj is Occurrence && Equals((Occurrence) obj);
37+
return obj is Occurrence occurrence && Equals(occurrence);
3738
}
3839

3940
public override int GetHashCode()
@@ -44,21 +45,7 @@ public override int GetHashCode()
4445
}
4546
}
4647

47-
public override string ToString()
48-
{
49-
var s = "Occurrence";
50-
if (Source != null)
51-
{
52-
s = Source.GetType().Name + " ";
53-
}
54-
55-
if (Period != null)
56-
{
57-
s += "(" + Period.StartTime + ")";
58-
}
59-
60-
return s;
61-
}
48+
public override string ToString() => $"Occurrence {Source.GetType().Name} ({Period.StartTime})";
6249

63-
public int CompareTo(Occurrence other) => Period.CompareTo(other.Period);
64-
}
50+
public int CompareTo(Occurrence? other) => Period.CompareTo(other?.Period);
51+
}

Ical.Net/DataTypes/RequestStatus.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
using System.IO;
78
using Ical.Net.Serialization.DataTypes;
89

@@ -13,23 +14,23 @@ namespace Ical.Net.DataTypes;
1314
/// </summary>
1415
public class RequestStatus : EncodableDataType
1516
{
16-
private string _mDescription;
17-
private string _mExtraData;
18-
private StatusCode _mStatusCode;
17+
private string? _mDescription;
18+
private string? _mExtraData;
19+
private StatusCode? _mStatusCode;
1920

20-
public virtual string Description
21+
public virtual string? Description
2122
{
2223
get => _mDescription;
2324
set => _mDescription = value;
2425
}
2526

26-
public virtual string ExtraData
27+
public virtual string? ExtraData
2728
{
2829
get => _mExtraData;
2930
set => _mExtraData = value;
3031
}
3132

32-
public virtual StatusCode StatusCode
33+
public virtual StatusCode? StatusCode
3334
{
3435
get => _mStatusCode;
3536
set => _mStatusCode = value;
@@ -40,7 +41,10 @@ public RequestStatus() { }
4041
public RequestStatus(string value) : this()
4142
{
4243
var serializer = new RequestStatusSerializer();
43-
CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
44+
if (serializer.Deserialize(new StringReader(value)) is ICopyable deserializedObject)
45+
{
46+
CopyFrom(deserializedObject);
47+
}
4448
}
4549

4650
/// <inheritdoc/>
@@ -52,10 +56,7 @@ public override void CopyFrom(ICopyable obj)
5256
return;
5357
}
5458

55-
if (rs.StatusCode != null)
56-
{
57-
StatusCode = rs.StatusCode;
58-
}
59+
StatusCode = rs.StatusCode;
5960
Description = rs.Description;
6061
ExtraData = rs.ExtraData;
6162
}
@@ -69,7 +70,7 @@ public override string ToString()
6970
protected bool Equals(RequestStatus other) => string.Equals(_mDescription, other._mDescription) && string.Equals(_mExtraData, other._mExtraData) &&
7071
Equals(_mStatusCode, other._mStatusCode);
7172

72-
public override bool Equals(object obj)
73+
public override bool Equals(object? obj)
7374
{
7475
if (ReferenceEquals(null, obj))
7576
{
@@ -96,4 +97,4 @@ public override int GetHashCode()
9697
return hashCode;
9798
}
9899
}
99-
}
100+
}

Ical.Net/DataTypes/StatusCode.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
using System.IO;
78
using System.Linq;
89
using Ical.Net.Serialization.DataTypes;
@@ -37,7 +38,10 @@ public int Primary
3738
? Parts[2]
3839
: 0;
3940

40-
public StatusCode() { }
41+
public StatusCode()
42+
{
43+
Parts = System.Array.Empty<int>();
44+
}
4145

4246
public StatusCode(int[] parts)
4347
{
@@ -47,7 +51,11 @@ public StatusCode(int[] parts)
4751
public StatusCode(string value) : this()
4852
{
4953
var serializer = new StatusCodeSerializer();
50-
CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
54+
var deserialized = serializer.Deserialize(new StringReader(value)) as ICopyable;
55+
if (deserialized != null)
56+
{
57+
CopyFrom(deserialized);
58+
}
5159
}
5260

5361
/// <inheritdoc/>
@@ -64,7 +72,7 @@ public override void CopyFrom(ICopyable obj)
6472

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

67-
public override bool Equals(object obj)
75+
public override bool Equals(object? obj)
6876
{
6977
if (ReferenceEquals(null, obj))
7078
{
@@ -82,4 +90,4 @@ public override bool Equals(object obj)
8290
}
8391

8492
public override int GetHashCode() => CollectionHelpers.GetHashCode(Parts);
85-
}
93+
}

Ical.Net/DataTypes/Trigger.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
using System;
78
using System.IO;
89
using Ical.Net.Serialization.DataTypes;
@@ -15,11 +16,11 @@ namespace Ical.Net.DataTypes;
1516
/// </summary>
1617
public class Trigger : EncodableDataType
1718
{
18-
private CalDateTime _mDateTime;
19+
private CalDateTime? _mDateTime;
1920
private Duration? _mDuration;
2021
private string _mRelated = TriggerRelation.Start;
2122

22-
public virtual CalDateTime DateTime
23+
public virtual CalDateTime? DateTime
2324
{
2425
get => _mDateTime;
2526
set
@@ -30,9 +31,6 @@ public virtual CalDateTime DateTime
3031
return;
3132
}
3233

33-
// NOTE: this, along with the "Duration" setter, fixes the bug tested in
34-
// TODO11(), as well as this thread: https://sourceforge.net/forum/forum.php?thread_id=1926742&forum_id=656447
35-
3634
// DateTime and Duration are mutually exclusive
3735
Duration = null;
3836

@@ -52,8 +50,6 @@ public virtual Duration? Duration
5250
_mDuration = value;
5351
if (_mDuration != null)
5452
{
55-
// NOTE: see above.
56-
5753
// DateTime and Duration are mutually exclusive
5854
DateTime = null;
5955
}
@@ -78,7 +74,10 @@ public Trigger(Duration ts)
7874
public Trigger(string value) : this()
7975
{
8076
var serializer = new TriggerSerializer();
81-
CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
77+
if (serializer.Deserialize(new StringReader(value)) is ICopyable deserializedObject)
78+
{
79+
CopyFrom(deserializedObject);
80+
}
8281
}
8382

8483
/// <inheritdoc/>
@@ -97,7 +96,7 @@ public override void CopyFrom(ICopyable obj)
9796

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

100-
public override bool Equals(object obj)
99+
public override bool Equals(object? obj)
101100
{
102101
if (ReferenceEquals(null, obj))
103102
{

Ical.Net/DataTypes/UTCOffset.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44
//
55

6+
#nullable enable
67
using System;
78
using Ical.Net.Serialization.DataTypes;
89

@@ -45,7 +46,7 @@ public UtcOffset(TimeSpan ts)
4546

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

48-
public override bool Equals(object obj)
49+
public override bool Equals(object? obj)
4950
{
5051
if (ReferenceEquals(null, obj))
5152
{
@@ -76,4 +77,4 @@ public override void CopyFrom(ICopyable obj)
7677
Offset = o.Offset;
7778
}
7879
}
79-
}
80+
}

0 commit comments

Comments
 (0)