InternetCalendar Class
Represents an iCalendar calendar containing events.
public sealed class InternetCalendarExample
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
| Name | Description |
|---|---|
| InternetCalendar() |
InternetCalendar()
InternetCalendar.cspublic InternetCalendar()No documentation is available.
Properties
| Name | Description |
|---|---|
| AdditionalProperties | Gets additional custom properties for the calendar, each value written according to the value type of its property. |
| Events | Gets the events in this calendar. |
| RawProperties | Gets the properties of the calendar that are written verbatim, in order, after InternetCalendar.AdditionalProperties. |
| Version | Gets or sets the iCalendar version. |
AdditionalProperties
InternetCalendar.csGets 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
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.
Events
InternetCalendar.csRawProperties
InternetCalendar.csGets 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.
Version
InternetCalendar.csGets or sets the iCalendar version.
public string Version { get; set; }Property value
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
| Name | Description |
|---|---|
| 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.csParses an iCalendar object (RFC 5545) read from a stream as UTF-8.
public static InternetCalendar Parse(Stream stream)Parameters
streamStream- 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.csParses an iCalendar object (RFC 5545).
public static InternetCalendar Parse(TextReader reader)Parameters
readerTextReader- 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.csParses an iCalendar object (RFC 5545).
public static InternetCalendar Parse(ReadOnlySpan<char> ics)Parameters
icsReadOnlySpan<char>- The iCalendar content to parse.
Returns
InternetCalendar The parsed calendar.
Exceptions
FormatException- The content is not a valid iCalendar object.
Parse(string)
InternetCalendar.csParses an iCalendar object (RFC 5545).
public static InternetCalendar Parse(string ics)Parameters
icsstring- The iCalendar content to parse.
Returns
InternetCalendar The parsed calendar.
Exceptions
FormatException- The content is not a valid iCalendar object.
ToIcs overloads
ToIcs()
InternetCalendar.csToIcs(Stream)
InternetCalendar.csWrites the calendar to a stream in iCalendar format.
Parameters
streamStream- The stream to write to.
Remarks
Nothing is written when the calendar cannot be written: see InternetCalendar.ToIcs.
ToIcs(TextWriter)
InternetCalendar.csWrites the calendar to a text writer in iCalendar format.
public void ToIcs(TextWriter writer)Parameters
writerTextWriter- 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.csAttempts to parse an iCalendar object (RFC 5545).
public static bool TryParse(TextReader reader, out InternetCalendar? calendar, out string? error)Parameters
readerTextReader- The text reader to read the iCalendar content from.
calendarInternetCalendar?- When successful, contains the parsed calendar.
errorstring?- When parsing fails, contains the error message.
Returns
bool true if parsing succeeded; otherwise, false.
TryParse(ReadOnlySpan<char>, InternetCalendar?)
InternetCalendar.csAttempts to parse an iCalendar object (RFC 5545).
public static bool TryParse(ReadOnlySpan<char> ics, out InternetCalendar? calendar)Parameters
icsReadOnlySpan<char>- The iCalendar content to parse.
calendarInternetCalendar?- When successful, contains the parsed calendar.
Returns
bool true if parsing succeeded; otherwise, false.
TryParse(ReadOnlySpan<char>, InternetCalendar?, string?)
InternetCalendar.csAttempts to parse an iCalendar object (RFC 5545).
public static bool TryParse(ReadOnlySpan<char> ics, out InternetCalendar? calendar, out string? error)Parameters
icsReadOnlySpan<char>- The iCalendar content to parse.
calendarInternetCalendar?- When successful, contains the parsed calendar.
errorstring?- When parsing fails, contains the error message.
Returns
bool true if parsing succeeded; otherwise, false.
TryParse(string?, InternetCalendar?)
InternetCalendar.csAttempts to parse an iCalendar object (RFC 5545).
public static bool TryParse(string? ics, out InternetCalendar? calendar)Parameters
icsstring?- The iCalendar content to parse.
calendarInternetCalendar?- When successful, contains the parsed calendar.
Returns
bool true if parsing succeeded; otherwise, false.
TryParse(string?, InternetCalendar?, string?)
InternetCalendar.csAttempts to parse an iCalendar object (RFC 5545).
public static bool TryParse(string? ics, out InternetCalendar? calendar, out string? error)Parameters
icsstring?- The iCalendar content to parse.
calendarInternetCalendar?- When successful, contains the parsed calendar.
errorstring?- When parsing fails, contains the error message.
Returns
bool true if parsing succeeded; otherwise, false.