Skip to content
Merged
18 changes: 9 additions & 9 deletions Ical.Net.Tests/RecurrenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void EventOccurrenceTest(
""";

var cal = Calendar.Load(calendarIcalStr);
var tzid = cal.Events.Single().Start.TzId;
var tzid = cal.Events.Single().Start?.TzId;

var periodSerializer = new PeriodSerializer();
var periods = expectedPeriods
Expand Down Expand Up @@ -140,7 +140,7 @@ public void YearlyComplex1()

while (dt.Year < 2011)
{
if (dt.GreaterThan(evt.Start) &&
if (dt.GreaterThan(evt.Start!) &&
(dt.Year % 2 == 1) && // Every-other year from 2005
(dt.Month == 1) &&
(dt.DayOfWeek == DayOfWeek.Sunday))
Expand Down Expand Up @@ -203,7 +203,7 @@ public void DailyUntil1()
var i = 0;
while (dt.Year < 1998)
{
if (dt.GreaterThanOrEqual(evt.Start) &&
if (dt.GreaterThanOrEqual(evt.Start!) &&
dt.LessThan(new CalDateTime(1997, 12, 24, 0, 0, 0, _tzid)))
{
Assert.Multiple(() =>
Expand Down Expand Up @@ -375,7 +375,7 @@ public void ByMonth1()
var i = 0;
while (dt.Year < 2001)
{
if (dt.GreaterThanOrEqual(evt.Start) &&
if (dt.GreaterThanOrEqual(evt.Start!) &&
dt.Month == 1 &&
dt.LessThanOrEqual(new CalDateTime(2000, 1, 31, 9, 0, 0, _tzid)))
{
Expand Down Expand Up @@ -2337,7 +2337,7 @@ public void Yearly1()
public void Bug2912657()
{
var iCal = Calendar.Load(IcsFiles.Bug2912657);
var localTzid = iCal.Events.First().Start.TzId;
var localTzid = iCal.Events.First().Start?.TzId;

// Daily recurrence
EventOccurrenceTest(
Expand Down Expand Up @@ -2602,7 +2602,7 @@ public void DurationOfRecurrencesOverDst(string dtStart, string dtEnd, string? d
for (var index = 0; index < expectedPeriods.Length; index++)
{
var p = expectedPeriods[index];
var newStart = p.StartTime.ToTimeZone(start.TzId);
var newStart = p.StartTime.ToTimeZone(start?.TzId);
expectedPeriods[index] = Period.Create(newStart, end: newStart.Add(p.Duration!.Value));
}

Expand Down Expand Up @@ -2866,8 +2866,8 @@ public void UsHolidays()
Assert.That(evt, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(items.ContainsKey(evt.Summary), Is.True, "Holiday text '" + evt.Summary + "' did not match known holidays.");
Assert.That(o.Period.StartTime, Is.EqualTo(items[evt.Summary]), "Date/time of holiday '" + evt.Summary + "' did not match.");
Assert.That(items.ContainsKey(evt.Summary!), Is.True, "Holiday text '" + evt.Summary + "' did not match known holidays.");
Assert.That(o.Period.StartTime, Is.EqualTo(items[evt.Summary!]), "Date/time of holiday '" + evt.Summary + "' did not match.");
});
}
}
Expand Down Expand Up @@ -3904,7 +3904,7 @@ public void TestDtStartTimezone(string? tzId)
var cal = Calendar.Load(icalText);
var evt = cal.Events.First();
var ev = new EventEvaluator(evt);
var occurrences = ev.Evaluate(evt.DtStart, evt.DtStart.ToTimeZone(tzId), evt.DtStart.AddMinutes(61).ToTimeZone(tzId), null);
var occurrences = ev.Evaluate(evt.DtStart!, evt.DtStart!.ToTimeZone(tzId), evt.DtStart.AddMinutes(61).ToTimeZone(tzId), null);
var occurrencesStartTimes = occurrences.Select(x => x.StartTime).Take(2).ToList();

var expectedStartTimes = new[]
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/CalendarComponents/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
// Ensure that "FromDate" has already been set
if (fromDate == null)
{
fromDate = rc.Start.Copy();
fromDate = rc.Start?.Copy();

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

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/Alarm.cs#L94

Added line #L94 was not covered by tests
}

Duration? duration = null;
Expand Down
8 changes: 4 additions & 4 deletions Ical.Net/CalendarComponents/CalendarComponent.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 System.Runtime.Serialization;

Expand All @@ -18,7 +19,7 @@ public class CalendarComponent : CalendarObject, ICalendarComponent
/// <summary>
/// Returns a list of properties that are associated with the iCalendar object.
/// </summary>
public virtual CalendarPropertyList Properties { get; protected set; }
public virtual CalendarPropertyList Properties { get; protected set; } = null!;

public CalendarComponent() : base()
{
Expand Down Expand Up @@ -47,8 +48,7 @@ public override void CopyFrom(ICopyable obj)
{
base.CopyFrom(obj);

var c = obj as ICalendarComponent;
if (c == null)
if (obj is not ICalendarComponent c)
{
return;
}
Expand Down Expand Up @@ -78,4 +78,4 @@ public virtual void AddProperty(ICalendarProperty p)
p.Parent = this;
Properties.Set(p.Name, p.Value);
}
}
}
14 changes: 6 additions & 8 deletions Ical.Net/CalendarComponents/CalendarEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
/// Returns <see langword="true"/> if the event is an all-day event,
/// meaning the <see cref="RecurringComponent.Start"/> is a 'DATE' value type.
/// </summary>
public virtual bool IsAllDay => !Start.HasTime;
public virtual bool IsAllDay => Start?.HasTime == false;

/// <summary>
/// The geographic location (lat/long) of the event.
Expand Down Expand Up @@ -346,16 +346,14 @@
{
return 1;
}
if (DtStart.Equals(other.DtStart))
if (DtStart is null)
{
return 0;
return other.DtStart is null ? 0 : -1;
}
if (DtStart.LessThan(other.DtStart))
if (other.DtStart is null)
{
return -1;
return 1;

Check warning on line 355 in Ical.Net/CalendarComponents/CalendarEvent.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/CalendarEvent.cs#L355

Added line #L355 was not covered by tests
}

// meaning DtStart is greater than other
return 1;
return DtStart.CompareTo(other.DtStart);
}
}
30 changes: 13 additions & 17 deletions Ical.Net/CalendarComponents/FreeBusy.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 @@ -14,23 +15,23 @@

public class FreeBusy : UniqueComponent, IMergeable
{
public static FreeBusy Create(ICalendarObject obj, FreeBusy freeBusyRequest, EvaluationOptions options = default)
public static FreeBusy? Create(ICalendarObject obj, FreeBusy freeBusyRequest, EvaluationOptions? options = null)
{
if (!(obj is IGetOccurrencesTyped))
if ((obj is not IGetOccurrencesTyped occ))
{
return null;
}
var getOccurrences = (IGetOccurrencesTyped) obj;
var occurrences = getOccurrences.GetOccurrences<CalendarEvent>(freeBusyRequest.Start, freeBusyRequest.End, options);

var occurrences = occ.GetOccurrences<CalendarEvent>(freeBusyRequest.Start, freeBusyRequest.End, options);
var contacts = new List<string>();
var isFilteredByAttendees = false;

if (freeBusyRequest.Attendees != null && freeBusyRequest.Attendees.Count > 0)
if (freeBusyRequest.Attendees.Count > 0)
{
isFilteredByAttendees = true;
var attendees = freeBusyRequest.Attendees
.Where(a => a.Value != null)
.Select(a => a.Value.OriginalString.Trim());
.Select(a => a.Value!.OriginalString.Trim());

Check warning on line 34 in Ical.Net/CalendarComponents/FreeBusy.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/FreeBusy.cs#L34

Added line #L34 was not covered by tests
contacts.AddRange(attendees);
}

Expand All @@ -41,12 +42,8 @@

foreach (var o in occurrences)
{
var uc = o.Source as IUniqueComponent;

if (uc == null)
{
if (o.Source is not IUniqueComponent uc)
continue;
}

var evt = uc as CalendarEvent;
var accepted = false;
Expand All @@ -68,8 +65,7 @@
var participatingAttendeeQuery = uc.Attendees
.Where(attendee =>
attendee.Value != null
&& contacts.Contains(attendee.Value.OriginalString.Trim())
&& attendee.ParticipationStatus != null)
&& contacts.Contains(attendee.Value.OriginalString.Trim()))
.Select(pa => pa.ParticipationStatus.ToUpperInvariant());

foreach (var participatingAttendee in participatingAttendeeQuery)
Expand Down Expand Up @@ -98,7 +94,7 @@
return fb;
}

public static FreeBusy CreateRequest(CalDateTime fromInclusive, CalDateTime toExclusive, Organizer organizer, IEnumerable<Attendee> contacts)
public static FreeBusy CreateRequest(CalDateTime fromInclusive, CalDateTime toExclusive, Organizer? organizer, IEnumerable<Attendee>? contacts)
{
var fb = new FreeBusy
{
Expand Down Expand Up @@ -158,7 +154,7 @@
set => Properties.Set("DTEND", value);
}

public virtual FreeBusyStatus GetFreeBusyStatus(Period period)
public virtual FreeBusyStatus GetFreeBusyStatus(Period? period)
{
var status = FreeBusyStatus.Free;
if (period == null)
Expand All @@ -173,7 +169,7 @@
return status;
}

public virtual FreeBusyStatus GetFreeBusyStatus(CalDateTime dt)
public virtual FreeBusyStatus GetFreeBusyStatus(CalDateTime? dt)
{
var status = FreeBusyStatus.Free;
if (dt == null)
Expand All @@ -190,7 +186,7 @@

public virtual void MergeWith(IMergeable obj)
{
if (!(obj is FreeBusy fb))
if (obj is not FreeBusy fb)
{
return;
}
Expand Down
7 changes: 4 additions & 3 deletions Ical.Net/CalendarComponents/IAlarmContainer.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.Collections.Generic;
using Ical.Net.DataTypes;

Expand All @@ -16,13 +17,13 @@ public interface IAlarmContainer
ICalendarObjectList<Alarm> Alarms { get; }

/// <summary>
/// Polls <see cref="Alarm"/>s for occurrences within the <see cref="Evaluate"/>d
/// Polls <see cref="Alarm"/>s for occurrences within the <see cref="RecurringComponent.GetOccurrences"/>d
/// time frame of this <see cref="RecurringComponent"/>. For each evaluated
/// occurrence if this component, each <see cref="Alarm"/> is polled for its
/// corresponding alarm occurrences.
/// </summary>
/// <param name="startTime">The earliest allowable alarm occurrence to poll, or <c>null</c>.</param>
/// <param name="endTime"></param>
/// <returns>A List of <see cref="AlarmOccurrence"/> objects, one for each occurrence of the <see cref="Alarm"/>.</returns>
IList<AlarmOccurrence> PollAlarms(CalDateTime startTime, CalDateTime endTime);
}
IList<AlarmOccurrence> PollAlarms(CalDateTime? startTime, CalDateTime? endTime);
}
3 changes: 2 additions & 1 deletion Ical.Net/CalendarComponents/ICalendarComponent.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.CalendarComponents;

public interface ICalendarComponent : ICalendarPropertyListContainer { }
public interface ICalendarComponent : ICalendarPropertyListContainer { }
7 changes: 4 additions & 3 deletions Ical.Net/CalendarComponents/IRecurrable.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.Collections.Generic;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;
Expand All @@ -14,12 +15,12 @@ public interface IRecurrable : IGetOccurrences
/// <summary>
/// Gets/sets the start date/time of the component.
/// </summary>
CalDateTime Start { get; set; }
CalDateTime? Start { get; set; }

ExceptionDates ExceptionDates { get; }
IList<RecurrencePattern> ExceptionRules { get; set; }
RecurrenceDates RecurrenceDates { get; }
IList<RecurrencePattern> RecurrenceRules { get; set; }
CalDateTime RecurrenceId { get; set; }
IEvaluator Evaluator { get; }
CalDateTime? RecurrenceId { get; set; }
IEvaluator? Evaluator { get; }
}
13 changes: 7 additions & 6 deletions Ical.Net/CalendarComponents/IRecurringComponent.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.Collections.Generic;
using Ical.Net.DataTypes;

Expand All @@ -12,13 +13,13 @@ public interface IRecurringComponent : IUniqueComponent, IRecurrable
{
IList<Attachment> Attachments { get; set; }
IList<string> Categories { get; set; }
string Class { get; set; }
string? Class { get; set; }
IList<string> Contacts { get; set; }
CalDateTime Created { get; set; }
string Description { get; set; }
CalDateTime LastModified { get; set; }
CalDateTime? Created { get; set; }
string? Description { get; set; }
CalDateTime? LastModified { get; set; }
int Priority { get; set; }
IList<string> RelatedComponents { get; set; }
int Sequence { get; set; }
string Summary { get; set; }
}
string? Summary { get; set; }
}
11 changes: 6 additions & 5 deletions Ical.Net/CalendarComponents/IUniqueComponent.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 Ical.Net.DataTypes;
Expand All @@ -11,12 +12,12 @@ namespace Ical.Net.CalendarComponents;

public interface IUniqueComponent : ICalendarComponent
{
string Uid { get; set; }
string? Uid { get; set; }

IList<Attendee> Attendees { get; set; }
IList<string> Comments { get; set; }
CalDateTime DtStamp { get; set; }
Organizer Organizer { get; set; }
CalDateTime? DtStamp { get; set; }
Organizer? Organizer { get; set; }
IList<RequestStatus> RequestStatuses { get; set; }
Uri Url { get; set; }
}
Uri? Url { get; set; }
}
13 changes: 11 additions & 2 deletions Ical.Net/CalendarComponents/Journal.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.Runtime.Serialization;
using Ical.Net.Evaluation;

Expand Down Expand Up @@ -35,9 +36,17 @@
base.OnDeserializing(context);
}

protected bool Equals(Journal other) => Start.Equals(other.Start) && Equals(other as RecurringComponent);
protected bool Equals(Journal? other)
{
if (Start == null || other?.Start == null)
{
return Start == other?.Start; // Both must be null to be considered equal

Check warning on line 43 in Ical.Net/CalendarComponents/Journal.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/Journal.cs#L43

Added line #L43 was not covered by tests
}

return Start.Equals(other.Start) && Equals(other as RecurringComponent);
}

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 Down
Loading
Loading