|
using System;
using System.Configuration;
using System.Xml;
namespace ConfigSections
{
/// <summary>
/// MyConfigHandler - Implements IConfigurationSectionHandler.
/// This handler used to handle the companyAddress section of app.config
/// </summary>
public class MyConfigHandler:IConfigurationSectionHandler
{
public MyConfigHandler() { }
#region IConfigurationSectionHandler Members
//This is the only function defined in the interface IConfigurationSectionHandler
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
/* Parameter section will have all information about companyAddress,
* parst it and assign the values to CCompanyAddr object
*/
CCompanyAddr objCompany=new CCompanyAddr();
objCompany.CompanyName = section.SelectSingleNode("companyName").InnerText;
objCompany.DoorNo = section.SelectSingleNode("doorNo").InnerText;
objCompany.Street = section.SelectSingleNode("street").InnerText;
objCompany.City = section.SelectSingleNode("city").InnerText;
objCompany.PostalCode = Convert.ToInt64(section.SelectSingleNode("postalCode").InnerText);
objCompany.Country = section.SelectSingleNode("country").InnerText;
return objCompany;
}
#endregion
}
//CompanyAddress Class
/// <summary>
/// This is simple class to maintain the company address.
/// I am using this class in MyConfigHandler
/// </summary>
public class CCompanyAddr
{
#region private variables
private string _CompanyName;
private string _DoorNo;
private string _Street;
private string _City;
private long _PostalCode;
private string _Country;
#endregion
public CCompanyAddr()
{
_CompanyName=_DoorNo=_City=_Street=_Country="";
_PostalCode=0;
}
#region Properties
public string CompanyName
{
get{
return _CompanyName;
}
set{
_CompanyName = value;
}
}
public string DoorNo
{
get{
return _DoorNo;
}
set{
_DoorNo = value;
}
}
public string Street
{
get{
return _Street;
}
set{
_Street = value;
}
}
public string City
{
get{
return _City;
}
set{
_City = value;
}
}
public long PostalCode
{
get{
return _PostalCode;
}
set{
_PostalCode = value;
}
}
public string Country
{
get{
return _Country;
}
set{
_Country = value;
}
}
#endregion
}
}
|
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.