Here's a nifty way to build a Value Object for consumption across your app and then have access to each type as a collection.
public sealed class StreetTypes
{
private string _name;
private string _abbreviation;
public string Name
{
get { return _name; }
}
public string Abbreviation
{
get { return _abbreviation; }
}
private StreetTypes()
{
}
private StreetTypes(string name, string abbreviation)
{
_name = name;
_abbreviation = abbreviation;
}
private static IList<T> All<T>(T obj)
{
IList<T> types = new List<T>();
FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (FieldInfo field in fields)
{
if (field.FieldType.Equals(typeof(T)))
{
types.Add((T)field.GetValue(obj));
}
}
return types;
}
public static readonly StreetTypes ACCESS_ROAD = new StreetTypes("Access Road", "AcRd");
public static readonly StreetTypes ALLEY = new StreetTypes("Alley", "Aly");
public static readonly StreetTypes AVENUE = new StreetTypes("Avenue", "Ave");
public static readonly StreetTypes BOULEVARD = new StreetTypes("Boulevard", "Blvd");
public static readonly StreetTypes BRIDGE = new StreetTypes("Bridge", "Brg");
public static readonly StreetTypes CIRCLE = new StreetTypes("Circle", "Cir");
public static readonly StreetTypes COURT = new StreetTypes("Court", "Ct");
public static readonly StreetTypes CUTOFF = new StreetTypes("Cutoff", "Cto");
public static readonly StreetTypes DRIVE = new StreetTypes("Drive", "Dr");
public static readonly StreetTypes EXPRESSWAY = new StreetTypes("Expressway", "Expy");
public static readonly StreetTypes EXTENSION = new StreetTypes("Extension", "Ext");
public static readonly StreetTypes FREEWAY = new StreetTypes("Freeway", "Fwy");
public static readonly StreetTypes HIGHWAY = new StreetTypes("Highway", "Hwy");
public static readonly StreetTypes KEY = new StreetTypes("Key", "Ky");
public static readonly StreetTypes LANE = new StreetTypes("Lane", "Ln");
public static readonly StreetTypes LOOP = new StreetTypes("Loop", "Loop");
public static readonly StreetTypes OVERPASS = new StreetTypes("Overpass", "Opas");
public static readonly StreetTypes PARK = new StreetTypes("Park", "Park");
public static readonly StreetTypes PARKWAY = new StreetTypes("Parkway", "Pkwy");
public static readonly StreetTypes RAMP = new StreetTypes("Ramp", "Ramp");
public static readonly StreetTypes ROAD = new StreetTypes("Road", "Rd");
public static readonly StreetTypes RISE = new StreetTypes("Rise", "Rise");
public static readonly StreetTypes STREET = new StreetTypes("Street", "St");
public static readonly StreetTypes TERRACE = new StreetTypes("Terrace", "Ter");
public static readonly StreetTypes TRAIL = new StreetTypes("Trail", "Trl");
public static readonly StreetTypes TUNNEL = new StreetTypes("Tunnel", "Tunl");
public static readonly StreetTypes WALK = new StreetTypes("Walk", "Walk");
public static readonly StreetTypes WAY = new StreetTypes("Way", "Way");
public static IList<StreetTypes> ALL
{
get
{
return All<StreetTypes>(new StreetTypes());
}
}
}