InternetCalendar Class

Represents an iCalendar calendar containing events.

public sealed class InternetCalendar

Example

var calendar = new InternetCalendar();
calendar.Events.Add(new Event
{
    Start = new DateTime(2024, 01, 02, 08, 00, 00, DateTimeKind.Utc),
    End = new DateTime(2024, 01, 02, 09, 00, 00, DateTimeKind.Utc),
    Summary = "Meeting",
});
var icsContent = calendar.ToIcs();

Assert.Contains("BEGIN:VEVENT", icsContent);
Assert.Contains("DTSTART:20240102T080000Z", icsContent);
Assert.Contains("SUMMARY:Meeting", icsContent);

Constructors

NameDescription
InternetCalendar()

InternetCalendar()

InternetCalendar.cs
public InternetCalendar()

No documentation is available.

Properties

NameDescription
AdditionalPropertiesGets additional custom properties for the calendar, each value written according to the value type of its property.
EventsGets the events in this calendar.
RawPropertiesGets the properties of the calendar that are written verbatim, in order, after InternetCalendar.AdditionalProperties.
VersionGets or sets the iCalendar version.

AdditionalProperties

InternetCalendar.cs

Gets additional custom properties for the calendar, each value written according to the value type of its property.

public IDictionary<string, string> AdditionalProperties { get; }

Property value

IDictionary<string, string>

Remarks

A property whose value type is TEXT (RFC 5545 section 3.3.11) — an X- property, a property RFC 5545 does not define, or a TEXT property such as METHOD — has its value escaped when written, so it cannot hold a structured value such as a list or a parameter; use InternetCalendar.RawProperties for those. The value of a property whose value type is not TEXT, such as SOURCE or REFRESH-INTERVAL, is written as is, its control characters dropped.

The parser stores a property here only when it carries no parameter, occurs once, has a single TEXT value, and that value is written back unchanged.

A property whose name is not a valid property name, or is BEGIN, END, VERSION or PRODID, is not written.

Gets the events in this calendar.

public IList<Event> Events { get; }

Property value

IList<Event>

RawProperties

InternetCalendar.cs

Gets the properties of the calendar that are written verbatim, in order, after InternetCalendar.AdditionalProperties.

public IList<InternetCalendarProperty> RawProperties { get; }

Property value

IList<InternetCalendarProperty>

Remarks

The parser stores here, as written, every calendar property the model does not represent and that InternetCalendar.AdditionalProperties does not hold: a property with parameters, a repeated one, one whose value type is not TEXT, or a TEXT value TEXT escaping would not write back unchanged.

A property named BEGIN, END, VERSION or PRODID is not written.

Gets or sets the iCalendar version.

public string Version { get; set; }

Property value

string

Remarks

The value is vers or minver;maxver (RFC 5545 section 3.7.4), so it is read and written as is rather than as TEXT. A version containing a control character other than a tab cannot be written, and InternetCalendar.ToIcs throws an InvalidOperationException before writing anything.

Methods

NameDescription
Parse(Stream)Parses an iCalendar object (RFC 5545) read from a stream as UTF-8.
Parse(TextReader)Parses an iCalendar object (RFC 5545).
Parse(ReadOnlySpan<char>)Parses an iCalendar object (RFC 5545).
Parse(string)Parses an iCalendar object (RFC 5545).
ToIcs()Converts the calendar to an iCalendar format string.
ToIcs(Stream)Writes the calendar to a stream in iCalendar format.
ToIcs(TextWriter)Writes the calendar to a text writer in iCalendar format.
TryParse(TextReader, InternetCalendar?, string?)Attempts to parse an iCalendar object (RFC 5545).
TryParse(ReadOnlySpan<char>, InternetCalendar?)Attempts to parse an iCalendar object (RFC 5545).
TryParse(ReadOnlySpan<char>, InternetCalendar?, string?)Attempts to parse an iCalendar object (RFC 5545).
TryParse(string?, InternetCalendar?)Attempts to parse an iCalendar object (RFC 5545).
TryParse(string?, InternetCalendar?, string?)Attempts to parse an iCalendar object (RFC 5545).

Parse overloads

Parse(Stream)

InternetCalendar.cs

Parses an iCalendar object (RFC 5545) read from a stream as UTF-8.

public static InternetCalendar Parse(Stream stream)
Parameters
stream Stream
The stream to read the iCalendar content from.
Returns

InternetCalendar The parsed calendar.

Exceptions
FormatException
The content is not a valid iCalendar object.

Parse(TextReader)

InternetCalendar.cs

Parses an iCalendar object (RFC 5545).

public static InternetCalendar Parse(TextReader reader)
Parameters
reader TextReader
The text reader to read the iCalendar content from.
Returns

InternetCalendar The parsed calendar.

Exceptions
FormatException
The content is not a valid iCalendar object.

Parse(ReadOnlySpan<char>)

InternetCalendar.cs

Parses an iCalendar object (RFC 5545).

public static InternetCalendar Parse(ReadOnlySpan<char> ics)
Parameters
ics ReadOnlySpan<char>
The iCalendar content to parse.
Returns

InternetCalendar The parsed calendar.

Exceptions
FormatException
The content is not a valid iCalendar object.

Parse(string)

InternetCalendar.cs

Parses an iCalendar object (RFC 5545).

public static InternetCalendar Parse(string ics)
Parameters
ics string
The iCalendar content to parse.
Returns

InternetCalendar The parsed calendar.

Exceptions
FormatException
The content is not a valid iCalendar object.

ToIcs overloads

Converts the calendar to an iCalendar format string.

public string ToIcs()
Returns

string The iCalendar format string representation of this calendar.

ToIcs(Stream)

InternetCalendar.cs

Writes the calendar to a stream in iCalendar format.

public void ToIcs(Stream stream)
Parameters
stream Stream
The stream to write to.
Remarks

Nothing is written when the calendar cannot be written: see InternetCalendar.ToIcs.

ToIcs(TextWriter)

InternetCalendar.cs

Writes the calendar to a text writer in iCalendar format.

public void ToIcs(TextWriter writer)
Parameters
writer TextWriter
The text writer to write to.
Remarks

Content lines longer than 75 octets are folded, as RFC 5545 section 3.1 recommends.

The calendar is formatted before anything is written, so a value that cannot be written, such as a Event.Status that is not a member of EventStatus, throws an InvalidOperationException without producing partial output.

TryParse overloads

TryParse(TextReader, InternetCalendar?, string?)

InternetCalendar.cs

Attempts to parse an iCalendar object (RFC 5545).

public static bool TryParse(TextReader reader, out InternetCalendar? calendar, out string? error)
Parameters
reader TextReader
The text reader to read the iCalendar content from.
calendar InternetCalendar?
When successful, contains the parsed calendar.
error string?
When parsing fails, contains the error message.
Returns

bool true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, InternetCalendar?)

InternetCalendar.cs

Attempts to parse an iCalendar object (RFC 5545).

public static bool TryParse(ReadOnlySpan<char> ics, out InternetCalendar? calendar)
Parameters
ics ReadOnlySpan<char>
The iCalendar content to parse.
calendar InternetCalendar?
When successful, contains the parsed calendar.
Returns

bool true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, InternetCalendar?, string?)

InternetCalendar.cs

Attempts to parse an iCalendar object (RFC 5545).

public static bool TryParse(ReadOnlySpan<char> ics, out InternetCalendar? calendar, out string? error)
Parameters
ics ReadOnlySpan<char>
The iCalendar content to parse.
calendar InternetCalendar?
When successful, contains the parsed calendar.
error string?
When parsing fails, contains the error message.
Returns

bool true if parsing succeeded; otherwise, false.

TryParse(string?, InternetCalendar?)

InternetCalendar.cs

Attempts to parse an iCalendar object (RFC 5545).

public static bool TryParse(string? ics, out InternetCalendar? calendar)
Parameters
ics string?
The iCalendar content to parse.
calendar InternetCalendar?
When successful, contains the parsed calendar.
Returns

bool true if parsing succeeded; otherwise, false.

TryParse(string?, InternetCalendar?, string?)

InternetCalendar.cs

Attempts to parse an iCalendar object (RFC 5545).

public static bool TryParse(string? ics, out InternetCalendar? calendar, out string? error)
Parameters
ics string?
The iCalendar content to parse.
calendar InternetCalendar?
When successful, contains the parsed calendar.
error string?
When parsing fails, contains the error message.
Returns

bool true if parsing succeeded; otherwise, false.