RecurrenceGetEnumerator Method

Get a type-safe Recurrence enumerator

Definition

Namespace: EWSoftware.PDI
Assembly: EWSoftware.PDI (in EWSoftware.PDI.dll) Version: 2023.1.2.0
public RecurrenceEnumerator GetEnumerator()

Return Value

RecurrenceEnumerator
A type-safe Recurrence enumerator

Remarks

Set up the recurrence pattern and the starting date before using the enumerator. It is best to use a recurrence that ends after a specific number of occurrences or a specific date. If enumerating one that does not end, it will go until it is about a year short of DateTime.MaxValue.

Note that this is not exposed via the IEnumerable interface. Instead, it is only used by foreach loop code or if called explicitly. As such, the object itself cannot be used as a data source for data binding. However, the DateTimeCollection returned by the InstancesBetween(DateTime, DateTime) and AllInstances methods can be used as a data source.

Example

C#
// Test daily recurrence
rRecur.RecurDaily(2);
rRecur.StartDateTime = DateTime.Today;
rRecur.RecurUntil = DateTime.Today.AddMonths(1);

// With a collection
DateTimeCollection recurDates = rRecur.InstancesBetween(DateTime.Today,
    DateTime.Today.AddMonths(1));

foreach(DateTime dt in recurDates)
    Console.WriteLine("Daily recurrence on: {0:d}", dt);

// Using the enumerator
foreach(DateTime dt in rRecur)
    Console.WriteLine("Daily recurrence on: {0:d}", dt);

See Also