Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Created January 13, 2012 06:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staxmanade/1604923 to your computer and use it in GitHub Desktop.
Save staxmanade/1604923 to your computer and use it in GitHub Desktop.
Sort of like an Enum with more data or behavior possibilities.
public class Sample
{
[Test]
public void MetadataSample()
{
Items.ItemA.ShouldEqual(Items.ItemA);
Items.ItemA.Description.ShouldEndWith("Description for A");
}
}
public class Items
{
private Items(int id, string description)
{
Id = id;
Description = description;
}
public int Id { get; private set; }
public string Description { get; private set; }
#region Equals Override
public bool Equals(Items other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return other.Id == Id;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (Items)) return false;
return Equals((Items) obj);
}
public override int GetHashCode()
{
return Id;
}
#endregion
public static readonly Items ItemA = new Items(1, "Description for A");
public static readonly Items ItemB = new Items(2, "Description for B");
public static readonly Items ItemC = new Items(3, "Description for C");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment