Skip to content

Commit c4c0eb0

Browse files
committed
Implemented changes from the code review
1 parent d3e90bc commit c4c0eb0

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Ical.Net.Tests/RecurrenceTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ int eventIndex
3030
)
3131
{
3232
var evt = cal.Events.Skip(eventIndex).First();
33+
var rule = evt.RecurrenceRules.FirstOrDefault();
34+
#pragma warning disable 0618
35+
if (rule != null) rule.RestrictionType = RecurrenceRestrictionType.NoRestriction;
36+
#pragma warning restore 0618
3337
fromDate.AssociatedObject = cal;
3438
toDate.AssociatedObject = cal;
3539

@@ -2767,6 +2771,9 @@ public void Evaluate1(string freq, int secsPerInterval, bool hasTime)
27672771
// This case (DTSTART of type DATE and FREQ=MINUTELY) is undefined in RFC 5545.
27682772
// ical.net handles the case by pretending DTSTART has the time set to midnight.
27692773
evt.RecurrenceRules.Add(new RecurrencePattern($"FREQ={freq};INTERVAL=10;COUNT=5"));
2774+
#pragma warning disable 0618
2775+
evt.RecurrenceRules[0].RestrictionType = RecurrenceRestrictionType.NoRestriction;
2776+
#pragma warning restore 0618
27702777

27712778
var occurrences = evt.GetOccurrences(CalDateTime.Today.AddDays(-1), CalDateTime.Today.AddDays(100))
27722779
.OrderBy(x => x)
@@ -2791,6 +2798,9 @@ public void RecurrencePattern1()
27912798
// NOTE: evaluators are not generally meant to be used directly like this.
27922799
// However, this does make a good test to ensure they behave as they should.
27932800
var pattern = new RecurrencePattern("FREQ=SECONDLY;INTERVAL=10");
2801+
#pragma warning disable 0618
2802+
pattern.RestrictionType = RecurrenceRestrictionType.NoRestriction;
2803+
#pragma warning restore 0618
27942804

27952805
var us = new CultureInfo("en-US");
27962806

Ical.Net/DataTypes/RecurrencePattern.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ namespace Ical.Net.DataTypes
1515
public class RecurrencePattern : EncodableDataType
1616
{
1717
private int _interval = int.MinValue;
18+
#pragma warning disable 0618
1819
private RecurrenceRestrictionType? _restrictionType;
1920
private RecurrenceEvaluationModeType? _evaluationMode;
20-
21+
#pragma warning restore 0618
2122
public FrequencyType Frequency { get; set; }
2223

2324
private DateTime _until = DateTime.MinValue;
@@ -84,6 +85,7 @@ public int Interval
8485

8586
public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Monday;
8687

88+
#pragma warning disable 0618
8789
/// <summary>
8890
/// The type of restriction to apply to the evaluation of this recurrence pattern.
8991
/// Returns <see cref="RecurrenceRestrictionType.NoRestriction"/> if not set.
@@ -98,7 +100,7 @@ public RecurrenceRestrictionType RestrictionType
98100
{
99101
return _restrictionType.Value;
100102
}
101-
return RecurrenceRestrictionType.NoRestriction;
103+
return Calendar?.RecurrenceRestriction ?? RecurrenceRestrictionType.Default;
102104
}
103105
set => _restrictionType = value;
104106
}
@@ -117,6 +119,7 @@ public RecurrenceEvaluationModeType EvaluationMode
117119
}
118120
set => _evaluationMode = value;
119121
}
122+
#pragma warning restore 0618
120123

121124
public RecurrencePattern()
122125
{
@@ -148,8 +151,10 @@ public override string ToString()
148151
}
149152

150153
protected bool Equals(RecurrencePattern other) => (Interval == other.Interval)
154+
#pragma warning disable 0618
151155
&& RestrictionType == other.RestrictionType
152156
&& EvaluationMode == other.EvaluationMode
157+
#pragma warning restore 0618
153158
&& Frequency == other.Frequency
154159
&& Until.Equals(other.Until)
155160
&& Count == other.Count
@@ -176,8 +181,10 @@ public override int GetHashCode()
176181
unchecked
177182
{
178183
var hashCode = Interval.GetHashCode();
184+
#pragma warning disable 0618
179185
hashCode = (hashCode * 397) ^ RestrictionType.GetHashCode();
180186
hashCode = (hashCode * 397) ^ EvaluationMode.GetHashCode();
187+
#pragma warning restore 0618
181188
hashCode = (hashCode * 397) ^ (int)Frequency;
182189
hashCode = (hashCode * 397) ^ Until.GetHashCode();
183190
hashCode = (hashCode * 397) ^ Count;
@@ -218,8 +225,10 @@ public override void CopyFrom(ICopyable obj)
218225
ByMonth = new List<int>(r.ByMonth);
219226
BySetPosition = new List<int>(r.BySetPosition);
220227
FirstDayOfWeek = r.FirstDayOfWeek;
228+
#pragma warning disable 0618
221229
RestrictionType = r.RestrictionType;
222230
EvaluationMode = r.EvaluationMode;
231+
#pragma warning restore 0618
223232
}
224233

225234
private static bool CollectionEquals<T>(IEnumerable<T> c1, IEnumerable<T> c2) => c1.SequenceEqual(c2);

Ical.Net/Evaluation/RecurrencePatternEvaluator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private RecurrencePattern ProcessRecurrencePattern(IDateTime referenceDate)
135135

136136
return r;
137137
}
138-
138+
#pragma warning disable 0618
139139
private void EnforceEvaluationRestrictions(RecurrencePattern pattern)
140140
{
141141
RecurrenceEvaluationModeType? evaluationMode = pattern.EvaluationMode;
@@ -230,7 +230,7 @@ private void EnforceEvaluationRestrictions(RecurrencePattern pattern)
230230
}
231231
}
232232
}
233-
233+
#pragma warning 0618 restore
234234
/// <summary>
235235
/// Returns a list of start dates in the specified period represented by this recurrence pattern.
236236
/// This method includes a base date argument, which indicates the start of the first occurrence of this recurrence.

0 commit comments

Comments
 (0)