My idea is to create a Key, Value Pair Enum. Can someone comment on this approach? Especially on the static methods. Is it a good idea to overload static methods?
public class NameValueEnum<K, V>
{
private K _key;
private V _value;
private static IList<NameValueEnum<K, V>> _list = new List<NameValueEnum<K, V>>();
private NameValueEnum() { }
public NameValueEnum(K key, V value)
{
this._key = key;
this._value = value;
_list.Add(this);
}
public static NameValueEnum<K, V> Parse(K key)
{
NameValueEnum<K, V> nve= null;
for (int i = 0; i < _list.Count - 1; i++)
{
nve = _list[i];
if (nve._key.Equals(key))
{
return nve;
}
}
return null;
}
public static NameValueEnum<K, V> Parse(V value)
{
NameValueEnum<K, V> nve = null;
for (int i = 0; i < _list.Count - 1; i++)
{
nve = _list[i];
if (nve._value.Equals(value))
{
return nve;
}
}
return null;
}
}
public sealed class Status : NameValueEnum<string, Guid>
{
public static Status Active =
new Status("Active", new Guid("506182B0-A123-4C21-BD2B-B758F6F635F3"));
public static Status InActive =
new Status("In-Active", new Guid("D83FAFF8-69B0-4CC8-BE24-B28B47D11A01"));
public static Status Suspended =
new Status("Suspended", new Guid("8FDE34CB-DB0F-47C8-B8AA-0C7D269CD0C9"));
private Status(String Key, Guid Value) : base(Key, Value) {}
public static new Status Parse(String key)
{
return (Status)NameValueEnum<String, Guid>.Parse(key);
}
public static new Status Parse(Guid value)
{
return (Status)NameValueEnum<String, Guid>.Parse(value);
}
}
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.f1();
}
private void f1()
{
Status s =
Status.Parse(new Guid("506182B0-A123-4C21-BD2B-B758F6F635F3"));
}
}