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
6 changes: 3 additions & 3 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 @@ -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
14 changes: 8 additions & 6 deletions Ical.Net/CalendarComponents/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/// </summary>
public class Alarm : CalendarComponent
{
public virtual string Action
public virtual string? Action
{
get => Properties.Get<string>(AlarmAction.Key);
set => Properties.Set(AlarmAction.Key, value);
}

public virtual Attachment Attachment
public virtual Attachment? Attachment
{
get => Properties.Get<Attachment>("ATTACH");
set => Properties.Set("ATTACH", value);
Expand All @@ -35,13 +35,13 @@
set => Properties.Set("ATTENDEE", value);
}

public virtual string Description
public virtual string? Description
{
get => Properties.Get<string>("DESCRIPTION");
set => Properties.Set("DESCRIPTION", value);
}

public virtual Duration Duration
public virtual Duration? Duration
{
get => Properties.Get<Duration>("DURATION");
set => Properties.Set("DURATION", value);
Expand All @@ -53,7 +53,7 @@
set => Properties.Set("REPEAT", value);
}

public virtual string Summary
public virtual string? Summary
{
get => Properties.Get<string>("SUMMARY");
set => Properties.Set("SUMMARY", value);
Expand Down Expand Up @@ -182,7 +182,9 @@

for (var j = 0; j < Repeat; j++)
{
alarmTime = alarmTime?.Add(Duration);
if (Duration != null)
alarmTime = alarmTime?.Add(Duration.Value);

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

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/Alarm.cs#L186

Added line #L186 was not covered by tests

if (alarmTime != null)
{
occurrences.Add(new AlarmOccurrence(this, alarmTime.Copy(), ao.Component));
Expand Down
28 changes: 7 additions & 21 deletions Ical.Net/CalendarComponents/CalendarEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void SetProperty<T>(string group, T value)
/// </summary>
public virtual CalDateTime? DtEnd
{
get => Properties.Get<CalDateTime?>("DTEND");
get => Properties.Get<CalDateTime>("DTEND");
set
{
if (Duration is not null) throw new InvalidOperationException("DTEND property cannot be set when DURATION property is not null.");
Expand All @@ -82,6 +82,7 @@ public virtual CalDateTime? DtEnd
/// </remarks>
public virtual Duration? Duration
{
// Duration is a struct, so we need to use Nullable<Duration> to allow null values
get => Properties.Get<Duration?>("DURATION");
set
{
Expand Down Expand Up @@ -181,7 +182,7 @@ public virtual CalDateTime? End
/// </summary>
public virtual GeographicLocation? GeographicLocation
{
get => Properties.Get<GeographicLocation?>("GEO");
get => Properties.Get<GeographicLocation>("GEO");
set => SetProperty("GEO", value);
}

Expand All @@ -190,7 +191,7 @@ public virtual GeographicLocation? GeographicLocation
/// </summary>
public virtual string? Location
{
get => Properties.Get<string?>("LOCATION");
get => Properties.Get<string>("LOCATION");
set => SetProperty("LOCATION", value);
}

Expand All @@ -212,7 +213,7 @@ public virtual IList<string> Resources
/// </summary>
public virtual string? Status
{
get => Properties.Get<string?>("STATUS");
get => Properties.Get<string>("STATUS");
set => SetProperty("STATUS", value);
}

Expand All @@ -225,7 +226,7 @@ public virtual string? Status
/// </summary>
public virtual string? Transparency
{
get => Properties.Get<string?>(TransparencyType.Key);
get => Properties.Get<string>(TransparencyType.Key);
set => SetProperty(TransparencyType.Key, value);
}

Expand Down Expand Up @@ -340,20 +341,5 @@ public override int GetHashCode()
}

/// <inheritdoc/>
public int CompareTo(CalendarEvent? other)
{
if (other is null)
{
return 1;
}
if (DtStart is null)
{
return other.DtStart is null ? 0 : -1;
}
if (other.DtStart is null)
{
return 1;
}
return DtStart.CompareTo(other.DtStart);
}
public int CompareTo(CalendarEvent? other) => DtStart?.CompareTo(other?.DtStart) ?? -1;
}
8 changes: 4 additions & 4 deletions Ical.Net/CalendarComponents/FreeBusy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,25 @@ public virtual IList<FreeBusyEntry> Entries
set => Properties.Set("FREEBUSY", value);
}

public virtual CalDateTime DtStart
public virtual CalDateTime? DtStart
{
get => Properties.Get<CalDateTime>("DTSTART");
set => Properties.Set("DTSTART", value);
}

public virtual CalDateTime DtEnd
public virtual CalDateTime? DtEnd
{
get => Properties.Get<CalDateTime>("DTEND");
set => Properties.Set("DTEND", value);
}

public virtual CalDateTime Start
public virtual CalDateTime? Start
{
get => Properties.Get<CalDateTime>("DTSTART");
set => Properties.Set("DTSTART", value);
}

public virtual CalDateTime End
public virtual CalDateTime? End
{
get => Properties.Get<CalDateTime>("DTEND");
set => Properties.Set("DTEND", value);
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/CalendarComponents/Journal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Ical.Net.CalendarComponents;
/// </summary>
public class Journal : RecurringComponent
{
public string Status
public string? Status
{
get => Properties.Get<string>(JournalStatus.Key);
set => Properties.Set(JournalStatus.Key, value);
Expand Down
4 changes: 2 additions & 2 deletions Ical.Net/CalendarComponents/Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public virtual IList<string> Resources
/// <summary>
/// The status of the item.
/// </summary>
public virtual string Status
public virtual string? Status
{
get => Properties.Get<string>(TodoStatus.Key);
set
Expand Down Expand Up @@ -171,7 +171,7 @@ public virtual bool IsActive(CalDateTime currDt)

protected override void OnDeserializing(StreamingContext context)
{
//ToDo: a necessary evil, for now
//A necessary evil, for now
base.OnDeserializing(context);
}
}
6 changes: 3 additions & 3 deletions Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@
Name = Components.Timezone;
}


public VTimeZone(string tzId) : this()
{
if (string.IsNullOrWhiteSpace(tzId))
Expand All @@ -301,7 +300,7 @@

private DateTimeZone _nodaZone = DateTimeZone.Utc; // must initialize
private string? _tzId;
public virtual string TzId
public virtual string? TzId
{
get
{
Expand All @@ -322,9 +321,10 @@
{
_tzId = null;
Properties.Remove("TZID");
return;

Check warning on line 324 in Ical.Net/CalendarComponents/VTimeZone.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/VTimeZone.cs#L324

Added line #L324 was not covered by tests
}

_nodaZone = DateUtil.GetZone(value);

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.
var id = _nodaZone.Id;
if (string.IsNullOrWhiteSpace(id))
{
Expand Down Expand Up @@ -384,7 +384,7 @@
unchecked
{
var hashCode = Name?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (TzId.GetHashCode());
hashCode = (hashCode * 397) ^ (TzId?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0);
return hashCode;
}
Expand Down
33 changes: 19 additions & 14 deletions Ical.Net/CalendarParameter.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.Diagnostics;
Expand All @@ -15,7 +16,7 @@
[DebuggerDisplay("{Name}={string.Join(\",\", Values)}")]
public class CalendarParameter : CalendarObject, IValueObject<string>
{
private HashSet<string> _values;
private HashSet<string> _values = new();

public CalendarParameter()
{
Expand All @@ -27,7 +28,7 @@
Initialize();
}

public CalendarParameter(string name, string value) : base(name)
public CalendarParameter(string name, string? value) : base(name)
{
Initialize();
AddValue(value);
Expand Down Expand Up @@ -72,7 +73,7 @@

public virtual bool ContainsValue(string value) => _values.Contains(value);

public virtual int ValueCount => _values?.Count ?? 0;
public virtual int ValueCount => _values.Count;

public virtual void SetValue(string value)
{
Expand All @@ -87,25 +88,29 @@
_values.UnionWith(values.Where(IsValidValue));
}

private bool IsValidValue(string value) => !string.IsNullOrWhiteSpace(value);
private static bool IsValidValue(string? value) => !string.IsNullOrWhiteSpace(value);

public virtual void AddValue(string value)
public virtual void AddValue(string? value)
{
if (!IsValidValue(value))
{
return;
}
_values.Add(value);
_values.Add(value!);
}

public virtual void RemoveValue(string value)
{
_values.Remove(value);
}
public virtual void RemoveValue(string value) => _values.Remove(value);

Check warning on line 102 in Ical.Net/CalendarParameter.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarParameter.cs#L102

Added line #L102 was not covered by tests

public virtual string Value
public virtual string? Value
{
get => Values?.FirstOrDefault();
set => SetValue(value);
get => Values.FirstOrDefault();
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value), "Value cannot be null.");

Check warning on line 111 in Ical.Net/CalendarParameter.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarParameter.cs#L111

Added line #L111 was not covered by tests
}
SetValue(value);
}

Check warning on line 114 in Ical.Net/CalendarParameter.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarParameter.cs#L113-L114

Added lines #L113 - L114 were not covered by tests
}
}
}
6 changes: 2 additions & 4 deletions Ical.Net/CalendarProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public virtual void AddParameter(string name, string value)
/// Adds a parameter to the iCalendar object.
/// </summary>
public virtual void AddParameter(CalendarParameter p)
{
Parameters.Add(p);
}
=> Parameters.Add(p);

/// <inheritdoc/>
public override void CopyFrom(ICopyable obj)
Expand Down Expand Up @@ -153,4 +151,4 @@ public virtual void RemoveValue(object value)
}
_values.Remove(value);
}
}
}
Loading
Loading