|
using System;
using System.Linq;
using i3Quest.Configuration.Core;
namespace i3Quest.Configuration
{
public class Person : IConfigurationElement
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
public PostalAddress MailingAddress { get; set; }
public void WriteConfiguration(IConfigurationContext context)
{
context["FirstName"] = FirstName;
context["LastName"] = LastName;
context["DateOfBirth"] = DateOfBirth.ToShortDateString();
if (MailingAddress != null)
{
// get existing or create new context
var ctx = context.Get("MailingAddress", true).First();
MailingAddress.WriteConfiguration(ctx);
}
}
public void ReadConfiguration(IConfigurationContext context)
{
FirstName = context["FirstName"];
LastName = context["LastName"];
DateTime dt;
DateTime.TryParse(context["DateOfBirth"], out dt);
DateOfBirth = dt;
var ctx = context.Get("MailingAddress", false).FirstOrDefault();
if (ctx != null)
{
MailingAddress = new PostalAddress();
MailingAddress.ReadConfiguration(ctx);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.