I have an enum
public enum ProductionStatus {
Received = 000,
Validated = 010,
PlannedAndConverted = 020,
InProduction = 030,
QAChecked
Here is universal helper class that will do reverse action - getting key by value from ANY Enum:
public static class EnumHelpers {
public static T GetEnumObjectByValue(int valueId) {
return (T) Enum.ToObject(typeof (T), valueId);
}
}
And it works like this - given we have this Enum:
public enum ShipmentStatus {
New = 0,
Shipped = 1,
Canceled = 2
}
So, to get Enum object ShipmentStatus.Shipped
this will return this object:
var enumObject = EnumHelpers.GetEnumObjectByValue(1);
So basicaly you can stick any Enum object and get it by value:
var enumObject = EnumHelpers.GetEnumObjectByValue(VALUE);