Click here to Skip to main content
15,893,337 members
Articles / Programming Languages / C#

Lightweight DB Framework

Rate me:
Please Sign up or sign in to vote.
3.63/5 (6 votes)
23 May 2006CPOL3 min read 40.9K   159   28  
Manage small database tables with lightweight and simple C# code. Best suited for PocketPC and Windows Mobile devices
using System;
using System.Xml;

namespace Reflective.LightWeightDB
{
	/// <summary>
	/// Represents a unique key that identifies a item in the data model
	/// </summary>
	public struct Key
	{
		private int _value;

		#region Constructors
		public Key(int _value)
		{
			this._value = _value;
		}
		#endregion

		#region Member Access
		public int Value
		{
			get
			{
				return _value;
			}
			set
			{
				_value = value;
			}
		}
		#endregion

		#region Serialization/Deserizlization
		public void Serialize(XmlTextWriter xmlWriter)
		{
			Serialize(xmlWriter, GetType().Name);
		}

		public void Serialize(XmlTextWriter xmlWriter, string elementName)
		{
			xmlWriter.WriteStartElement(elementName);

			xmlWriter.WriteElementString("value", XmlConvert.ToString(Value));

			xmlWriter.WriteEndElement();
		}

		static public Key DeserializeMembers(XmlNodeReader xmlReader)
		{
			Key key = new Key();
			xmlReader.ReadStartElement();
			key.Value = XmlConvert.ToInt32(xmlReader.ReadElementString());
			xmlReader.ReadEndElement();
			return key;
		}
		#endregion

		#region Operators
		// overload operator ==
		public static bool operator ==(Key a, Key b) 
		{
			return (a.Value == b.Value);
		}

		public static bool operator !=(Key a, Key b) 
		{
			return (a.Value != b.Value);
		}

		public override bool Equals(object obj)
		{
			return (Value == ((Key)obj).Value);
		}

		#endregion

		public Key GetNextKey()
		{
			Value++;
			return new Key(Value);
		}

		public override int GetHashCode()
		{
			return Value;
		}

		public override string ToString()
		{
			return Value.ToString ();
		}

		public bool Empty
		{
			get 
			{
				return (Value < 0);
			}
		}

	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions