Serialization and Deserialization of Calendars and Business Cards
The IT Hit Collab Library provides classes to serialize to iCalendar/vCard, jCalendar/jCard, hCalendar/hCard and xCalendar/xCard formats.
To serialize/deserialize to/from iCalendar and vCard formats you will use the vFormatter class. For jCalendar/jCard you will use the jFormatter. For hCalendar/hCard - hFormatter. For xCalendar/xCard - xFormatter.
ICard4 card = CardFactory.CreateCard4("My Corp");
IAddress4 adr = card.Addresses.CreateItem();
adr.Street = new[] { "1 Greentree" };
adr.Locality = new[] { "Sydnay" };
adr.Region = new[] { "New South Wales" };
adr.Country = new[] { "Australia" };
adr.PostalCode = new[] { "12345" };
adr.PreferenceLevel = 1;
adr.Types = new AddressType[] { AddressType.Work, AddressType.Postal };
card.Addresses.Add(adr);
string vCard = new vFormatter().Serialize(card);
Console.Write(vCard);
string jCard = new jFormatter().Serialize(card);
Console.Write(jCard);
string hCard = new hFormatter().Serialize(card);
Console.Write(hCard);
string xCard = new xFormatter().Serialize(card);
Console.Write(xCard);
vCard output:
BEGIN:VCARD VERSION:4.0 FN:My Corp ADR;PREF=1;TYPE=WORK,POSTAL:;;1 Greentree;Sydnay;New South Wales;12345;Aust ralia END:VCARD
jCard output:
[
"vcard",
[
"version",
{},
"text",
"4.0"
],
[
"fn",
{},
"text",
"My Corp"
],
[
"adr",
{
"pref": "1",
"type": [
"WORK",
"POSTAL"
]
},
"text",
[
"",
"",
"1 Greentree",
"Sydnay",
"New South Wales",
"12345",
"Australia"
]
]
]
hCard output:
<html>
<head>
</head>
<body>
<div class="vcard">
<div class="fn">
<span class="value">My Corp</span></div>
<div class="adr">
<span class="type">1</span>
<span class="type">WORK</span>
<span class="type">POSTAL</span>
<span class="post-office-box"></span>
<span class="extended-address"></span>
<span class="street-address">1 Greentree</span>
<span class="locality">Sydnay</span>
<span class="region">New South Wales</span>
<span class="postal-code">12345</span>
<span class="country-name">Australia</span></div></div></body></html>
xCard output:
<?xml version="1.0" encoding="utf-8"?>
<vcards xmlns="urn:ietf:params:xml:ns:vcard-4.0">
<vcard>
<fn>
<text>My Corp</text>
</fn>
<adr>
<parameters>
<pref>
<integer>1</integer>
</pref>
<type>
<text>WORK</text>
<text>POSTAL</text>
</type>
</parameters>
<post-office-box />
<extended-address />
<street-address>1 Greentree</street-address>
<locality>Sydnay</locality>
<region>New South Wales</region>
<postal-code>12345</postal-code>
<country-name>Australia</country-name>
</adr>
</vcard>
</vcards>