RecurrencePatternHelper
When working with saving recurrence patterns, the RadScheduler's API provides us with the RecurrencePatternHelper class. The helper provides two main functions - turning a recurrence pattern into a nicely serialized string for storage and producing a recurrence pattern when you provide that string back to it.
Serialize a RecurrencePattern to String
When you want to turn (serialize) a recurrence pattern into a string, then you need to use the RecurrencePatternHelper's RecurrencePatternToString() static method. The method accepts one argument - the pattern that must be serialized and returns the result string.
For example, consider the following RecurrencePattern declaration:
Example 1: RecurrencePattern declaration
var pattern = new RecurrencePattern()
{
Frequency = RecurrenceFrequency.Daily,
DaysOfWeekMask = RecurrenceDays.WeekDays,
Interval = 3,
MaxOccurrences = 10
};
The next code snippet demonstrates you how to use the RecurrencePatternToString() static method.
Example 2: Using the RecurrencePatternToString method
var serializedPattern = RecurrencePatternHelper.RecurrencePatternToString(pattern);
Deserialize a RecurrencePattern from String
When you want to produce (deserialize) a recurrence pattern from a string, then you need to use the RecurrencePatternHelper's TryParseRecurrencePattern static method. The method accepts two arguments:
The source string - the string which the recurrence pattern will be parsed from.
The second parameter is an out parameter. This is the parsed pattern.
Consider the serialized string from the previous example: FREQ=DAILY;COUNT=10;INTERVAL=3;BYDAY=MO,TU,WE,TH,FR. If you want to produce a recurrence pattern from that string, invoke the TryParseRecurrencePattern method like in the example below.
Example 3: Using the TryParseRecurrencePattern
var serializedPattern = "FREQ=DAILY;COUNT=10;INTERVAL=3;BYDAY=MO,TU,WE,TH,FR";
RecurrencePattern pattern;
RecurrencePatternHelper.TryParseRecurrencePattern(serializedPattern, out pattern);