|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.