public static class StringEnum
{
public static string GetStringValue(Enum value)
{
string output = null;
Type type = value.GetType();
FieldInfo fi = type.GetField(value.ToString());
StringValue[] attr = fi.GetCustomAttributes(typeof(StringValue), false) as StringValue[];
if (attr.Length > 0)
{
output = attr[0].Value;
}
return output;
}
}
StringEnum is a class which have (GetStringValue) method to get the string value.
public enum CampaignRequestType { [StringValue("None")] None = 0, [StringValue("Pharmacy Cards")] Pharmacy_Cards = 1,[StringValue("Prospect Campaign")] Prospect_Campaign = 2,[StringValue("Tradeshow/Advertising")] Tradeshow_Advertising = 3 }
its a enum...
string item = StringEnum.GetStringValue((Enumeration.CampaignRequestType)updateRequestStatus.RequestType_Code);
here (Enumeration.CampaignRequestType) is my enumeration and updateRequestStatus.RequestType_Code is data base field int type
i cast int value to enumeration type