Skip to content

QuickKVPLoad

Cinchoo edited this page Jun 24, 2017 · 3 revisions

Loading Key-Value (KVP) pair file

To load KVP file, use ChoKVPReader component to parse it. Sample below shows how to load ics file (sample.ics)

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:eralper@nosuchemail.com
DTSTART:20090306T140000Z
DTEND:20090306T150000Z
LOCATION:Meeting Room 1-D
TRANSP:OPAQUE
SEQUENCE:0
UID:040000008200E00074C5B7101A82E00800000000B09916C3F9ADC9010000000000000000100
0000099DFBC4731297248A2CAF0885C8C4856
DTSTAMP:20090326T080109Z
DESCRIPTION:A short discussion on topics related with upgrade of HiPath
ProCenter SDK Applications\n
SUMMARY:Upgrade HiPath ProCenter SDK Applications
PRIORITY:5
X-MICROSOFT-CDO-IMPORTANCE:1
CLASS:PUBLIC
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR

Load using iterator

using (var r = new ChoKVPReader(@"sample.ics"))
{
	r.Configuration.RecordStart = "BEGIN:VEVENT";
	r.Configuration.RecordEnd = "END:VEVENT";
	r.Configuration.IgnoreEmptyLine = true;
	r.Configuration.Comment = ";";
	foreach (dynamic item in r)
	{
		Console.WriteLine(item.SUMMARY);
	}
}

Load using loop

using (var r = new ChoKVPReader(@"sample.ics"))
{
	r.Configuration.RecordStart = "BEGIN:VEVENT";
	r.Configuration.RecordEnd = "END:VEVENT";
	r.Configuration.IgnoreEmptyLine = true;
	r.Configuration.Comment = ";";

	dynamic rec;
	while ((rec = r.Read()) != null)
	{
		Console.WriteLine(rec.SUMMARY);
	}
}

Load using POCO object

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
}
foreach (var e in new ChoJSONReader<Employee>("Emp.json"))
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);