From 4ab24157b293fb54a7d1592a9218366cc1bbe463 Mon Sep 17 00:00:00 2001 From: Markus Minichmayr Date: Tue, 10 Dec 2024 22:12:21 +0100 Subject: [PATCH] Remove remaining usages of MinValue and clean up related code (#668) * Replace use of `DateTime.MinValue` in RecurrencePatternEvaluator. * Simplify and avoid using reflection in CheckMutuallyExclusive() --- .../Evaluation/RecurrencePatternEvaluator.cs | 8 +++---- .../DataTypes/RecurrencePatternSerializer.cs | 21 ++++--------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs index 25993a26..8fdccc45 100644 --- a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs +++ b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs @@ -246,16 +246,16 @@ private IEnumerable EnumerateDates(DateTime originalDate, DateTime see var expandBehavior = RecurrenceUtil.GetExpandBehaviorList(pattern); var noCandidateIncrementCount = 0; - var candidate = DateTime.MinValue; + DateTime? candidate = null; var dateCount = 0; while (maxCount < 0 || dateCount < maxCount) { - if (pattern.Until is not null && candidate != DateTime.MinValue && candidate > pattern.Until) + if (pattern.Until is not null && candidate > pattern.Until) { break; } - if (candidate != DateTime.MinValue && candidate > periodEnd) + if (candidate > periodEnd) { break; } @@ -297,7 +297,7 @@ private IEnumerable EnumerateDates(DateTime originalDate, DateTime see if (pattern.Until is null || candidate <= pattern.Until) { - yield return candidate; + yield return candidate.Value; dateCount++; } } diff --git a/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs b/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs index 6990382d..0881b11f 100644 --- a/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs +++ b/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs @@ -88,24 +88,11 @@ public virtual void CheckRange(string name, int? value, int min, int max, bool a } } - public virtual void CheckMutuallyExclusive(string name1, string name2, T obj1, TU obj2) + public virtual void CheckMutuallyExclusive(string name1, string name2, T? obj1, TU? obj2) + where T : struct + where TU : struct { - if (Equals(obj1, default(T)) || Equals(obj2, default(TU))) - { - return; - } - // If the object is MinValue instead of its default, consider - // that to be unassigned. - - var t1 = obj1.GetType(); - var t2 = obj2.GetType(); - - var fi1 = t1.GetField("MinValue"); - var fi2 = t2.GetField("MinValue"); - - var isMin1 = fi1 != null && obj1.Equals(fi1.GetValue(null)); - var isMin2 = fi2 != null && obj2.Equals(fi2.GetValue(null)); - if (isMin1 || isMin2) + if ((obj1 == null) || (obj2 == null)) { return; }