Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 843425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:07:29+00:00 2026-05-15T06:07:29+00:00

I have the following enum defined. I have used underscores as this enum is

  • 0

I have the following enum defined. I have used underscores as this enum is used in logging and i don’t want to incur the overhead of reflection by using custom attribute.We use very heavy logging. Now requirement is to change “LoginFailed_InvalidAttempt1” to “LoginFailed Attempt1”. If i change this enum, i will have to change its value across application. I can replace underscore by a space inside logging SP. Is there any way by which i can change this without affecting whole application.Please suggest.

public enum ActionType
{
    None,
    Created,
    Modified,
    Activated,
    Inactivated,
    Deleted,
    Login,
    Logout,
    ChangePassword,
    ResetPassword,
    InvalidPassword,
    LoginFailed_LockedAccount,
    LoginFailed_InActiveAccount,
    LoginFailed_ExpiredAccount,
    ForgotPassword,
    LoginFailed_LockedAccount_InvalidAttempts,
    LoginFailed_InvalidAttempt1,
    LoginFailed_InvalidAttempt2,
    LoginFailed_InvalidAttempt3,
    ForgotPassword_InvalidAttempt1,
    ForgotPassword_InvalidAttempt2,
    ForgotPassword_InvalidAttempt3,
    SessionTimeOut,
    ForgotPassword_LockedAccount,
    LockedAccount,
    ReLogin,
    ChangePassword_Due_To_Expiration,
    ChangePassword_AutoExpired

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:07:30+00:00Added an answer on May 15, 2026 at 6:07 am

    The best way to do it will be with a Description attribute. I understand that you don’t use reflection, but you can always cache the result so it only happens once?

    Add the description attribute:

    [Description("LoginFailed Attempt1")]
    LoginFailed_InvalidAttempt1
    

    Then when displaying the text value of the enum, you can get the description out using the following bit of code:

    private static Dictionary<Type, Dictionary<Enum, string>> enumMaps = null;
    
    public static string GetDescription(Enum value)
    {
        Type eType = value.GetType();
        if (enumMaps == null)
        {
            enumMaps = new Dictionary<Type, Dictionary<Enum, string>> ();
        }
        Dictionary<Enum, string> map;
        if (enumMaps.ContainsKey(eType))
        {
            map = enumMaps[eType];
        }
        else
        {
            map = new Dictionary<Enum, string>();
            foreach (Enum e in Enum.GetValues(eType))
            {
                FieldInfo fi = eType.GetField(e.ToString());
                DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(
                    typeof(DescriptionAttribute), false);
                map[e] = (attributes.Length > 0) ? attributes[0].Description : e.ToString();
            }
            enumMaps[eType] = map;
        }
        return map[value];
    }
    

    As you can see from the code above, the reflection is only done once. Any subsequent calls on the same Enum value will return the result from a Dictionary which is lightning fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have the following enum: public enum Status implements StringEnum{ ONLINE(on),OFFLINE(off); private String status
Let's say I have the following simple enum: enum Response { Yes = 1,
I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION =
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have the following 2 macros: #define SCOPED_ENUM_HEADER(NAME) struct NAME{ enum _NAME{ #define SCOPED_ENUM_FOOTER(NAME)
I have a situation where I need the Checker enum below used in multiple
In my project, I have defined the an annotation similar to the following: (Omitting
I have a custom EL function defined as follows: <function> ... <function-signature> java.lang.String getAsText(com.test.Outerclass.InnerEnum)
I have following situation: I have loged user, standard authentication with DB table $authAdapter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.