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 7757301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:03:29+00:00 2026-06-01T13:03:29+00:00

I hope I can explain my problem in a way that it’s clear for

  • 0

I hope I can explain my problem in a way that it’s clear for everyone.
We need your suggestions on this.

We have an Enum Type which has more than 15 constants defined.
We receive a report from a web service and translate its one column into this Enum type.
And based on what we receive from that web service, we run specific functions using
Dictionary

Why am I asking for ideas?
Let’s say 3 of these Enum contants meet specific functions in our Dictionary but the rest use the same function. So, is there a way to add them into our Dictionary in a better way rather than adding them one by one? I also want to keep this structure because when it’s time, we might have specific functions in the future for the ones that I described as “the rest”.

To be more clear here’s an example what we’re trying to do:

Enum:

public enum Reason{
    ReasonA,
    ReasonB,
    ReasonC,
    ReasonD,
    ReasonE,
    ReasonF,
    ReasonG,
    ReasonH,
    ReasonI,
    ReasonJ,
    ReasonK
}

Defining our Dictionary:

public Dictionary<Reason, Action<CustomClassObj, string>> ReasonHandlers = new Dictionary<Reason, Action<CustomClassObj, string>>{
    { Reason.ReasonA, HandleReasonA },
    { Reason.ReasonB, HandleReasonB },
    { Reason.ReasonC, HandleReasonC },
    { Reason.ReasonD, HandleReasonGeneral },
    { Reason.ReasonE, HandleReasonGeneral },
    { Reason.ReasonF, HandleReasonGeneral },
    { Reason.ReasonG, HandleReasonGeneral },
    { Reason.ReasonH, HandleReasonGeneral },
    { Reason.ReasonI, HandleReasonGeneral },
    { Reason.ReasonJ, HandleReasonGeneral },
    { Reason.ReasonK, HandleReasonGeneral }
};

So basically what I’m asking is, is there a way to add Reason, Function pair more intelligently? Because as you can see after ReasonC, all other reasons use the same function.

Thank you for your suggestions.

  • 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-06-01T13:03:31+00:00Added an answer on June 1, 2026 at 1:03 pm

    You could try something like this, only put the custom Reason handler in the dictionary and then fallback to the General one.

    public Dictionary<Reason, Action<CustomClassObj, string>> ReasonHandlers = new Dictionary<Reason, Action<CustomClassObj, string>>{
        { Reason.ReasonA, HandleReasonA },
        { Reason.ReasonB, HandleReasonB },
        { Reason.ReasonC, HandleReasonC }};
    
    
    public Action<CustomClassObj, string> ReasonHandlerLookup (Reason reason) {
        Action<CustomClassObj, string> result = null;
        ReasonHandlers.TryGetValue(reason, out result);
        return result ?? HandleReasonGeneral;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope I can explain this right I have two input fields that require
I hope I can explain this clearly enough. I have my main form (A)
I hope I can explain this well enough so that you can understand the
I hope I can explain this properly. I'm making an android app that, when
This is in my opinion an abstract problem and I hope I can explain
I hope I can explain this clearly.. Is there a way to configure the
Hello I hope someone can explain this problem. This is the code: class Memory{
Image describing the problem http://img215.imageshack.us/img215/3725/20100314235127schedule2.jpg I hope the image above can explain what I
I hope I can explain this properly. I'm using flashDevelop for an avatar creation
I hope this I can explain what I am trying to achieve: I want

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.