Click here to Skip to main content
15,891,248 members
Articles / Programming Languages / C#

Implementing a PropertyBag in C#

Rate me:
Please Sign up or sign in to vote.
4.86/5 (23 votes)
25 Nov 200514 min read 210.1K   4.2K   119  
Designing and implementing a PropertyBag in C#.
using System;

using WebSoft;

namespace WebSoft
{
	/// <summary>
	/// The Address class serves as a demonstration general purpose class that
	/// uses an instance of PropertBag to enable the client to add ad-hoc 
	/// property values
	/// </summary>
	[Serializable()]
	public class Address
	{
		/// An instance of the PropertyBag class
		private PropertyBag objPropertyBag;

		/// fields for the general purpose classes in-built
		/// properties
		private string strLine1;
		private string strLine2;
		private string strLine3;
		private string strCity;
		private string strCounty;
		private string strCountry;
		private string strPostCode;

		/// <summary>
		/// Default Constructor
		/// </summary>
		public Address()
		{
			/// The PropertyBag instance is initialized; this is all
			/// a user of the PropertyBag class has to remember to do
			this.objPropertyBag = new PropertyBag(this);
		}

		/// <summary>
		/// The first line of the address
		/// </summary>
		public string Line1
		{
			get
			{
				return this.strLine1;
			}
			set
			{
				this.strLine1 = value;
			}
		}

		/// <summary>
		/// The second line of the address
		/// </summary>
		public string Line2
		{
			get
			{
				return this.strLine2;
			}
			set
			{
				this.strLine2 = value;
			}
		}

		/// <summary>
		/// The third line of the address
		/// </summary>
		public string Line3
		{
			get
			{
				return this.strLine3;
			}
			set
			{
				this.strLine3 = value;
			}
		}

		/// <summary>
		/// The city part of the address
		/// </summary>
		public string City
		{
			get
			{
				return this.strCity;
			}
			set
			{
				this.strCity = value;
			}
		}

		/// <summary>
		/// The county part of the address
		/// </summary>
		public string County
		{
			get
			{
				return this.strCounty;
			}
			set
			{
				this.strCounty = value;
			}
		}

		/// <summary>
		/// The country part of the address
		/// </summary>
		public string Country
		{
			get
			{
				return this.strCountry;
			}
			set
			{
				this.strCountry = value;
			}
		}

		/// <summary>
		/// The post code part of the address
		/// </summary>
		public string PostCode
		{
			get
			{
				return this.strPostCode;
			}
			set
			{
				this.strPostCode = value;
			}
		}

		/// <summary>
		/// The Address objects PropertyBag instance
		/// </summary>
		public PropertyBag Properties
		{
			get
			{
				return this.objPropertyBag;
			}
		}

	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
South Africa South Africa
Graham works as a senior developer / software architect for WebSoft Consultants Limited, devloping using a number of software technologies, concentrating on the C# / .NET technology set.

Areas of expertise include document management, n-tier enterprise business systems, and exploitation of workflow technology, as well as a wide range of development methodologies including agile model driven development, and UML.

Comments and Discussions