Extract Description From Enum

C#

using System.ComponentModel;
using System.Reflection;

...
..
.

            //  instantiate List of enum and add to it
            List<InvestorEmailAlertType> subscriptions = new List<InvestorEmailAlertType>();
            subscriptions.Add(InvestorEmailAlertType.AllCorporateNewsReleases);
            subscriptions.Add(InvestorEmailAlertType.FinancialNewsReleasesOnly);

          // Create another List of type string to hold Enum Descriptions
            List<string> subscriptionDesc = new List<string>();

            foreach (InvestorEmailAlertType subscriptionChoice in subscriptions)
            {
                subscriptionDesc.Add(GetEnumDescription(subscriptionChoice));
            }


    public static string GetEnumDescription(Enum value)
    {
        FieldInfo fi = value.GetType().GetField(value.ToString());
        DescriptionAttribute[] attributes =
              (DescriptionAttribute[])fi.GetCustomAttributes(
              typeof(DescriptionAttribute), false);
        return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
    }

InvestorEmailAlertType Enum

using System;
using System.ComponentModel;


public enum InvestorEmailAlertType
{
    [Description("All corporate news releases")]
    AllCorporateNewsReleases,

    [Description("Financial news releases only")]
    FinancialNewsReleasesOnly,

    [Description("Environmental news releases only")]
    EnvironmentalNewsReleasesOnly,

    [Description("Operations news releases only")]
    OperationsNewsReleasesOnly,

    [Description("All regional utility news releases")]
    AllRegionalUtilityNewsReleases,

    [Description("Investor presentation updates")]
    InvestorPresentationUpdates,

    [Description("Investor calendar updates")]
    InvestorCalendarUpdates,

    [Description("Financial webcast alerts")]
    FinancialWebcastAlerts,

    [Description("All SEC Filings")]
    AllSECFilings,

    [Description("Quarterly and Annual Reports")]
    QuarterlyAndAnnualReports,

    [Description("Insider Transactions")]
    InsiderTransactions,

    [Description("Quote By Email")]
    QuoteByEmail

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s