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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:24:16+00:00 2026-05-15T05:24:16+00:00

Say I have an enum something like: enum OrderStatus { AwaitingAuthorization, InProduction, AwaitingDespatch }

  • 0

Say I have an enum something like:

enum OrderStatus
{
    AwaitingAuthorization,
    InProduction,
    AwaitingDespatch
}

I’ve also created an extension method on my enum to tidy up the displayed values in the UI, so I have something like:

public static string ToDisplayString(this OrderStatus status)
{
    switch (status)
    {
        case Status.AwaitingAuthorization:
            return "Awaiting Authorization";

        case Status.InProduction:
            return "Item in Production";

        ... etc
    }
}

Inspired by the excellent post here, I want to bind my enums to a SelectList with an extension method:

public static SelectList ToSelectList<TEnum>(this TEnum enumObj)

however, to use the DisplayString values in the UI drop down I’d need to add a constraint along the lines of

: where TEnum has extension ToDisplayString

Obviously none of this is going to work at all with the current approach, unless there’s some clever trick I don’t know about.

Does anyone have any ideas about how I might be able to implement something like this?

  • 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-15T05:24:17+00:00Added an answer on May 15, 2026 at 5:24 am

    Is there a compelling reason to use an enum here?

    When you start jumping through crazy hoops to use enums, it might be time to use a class.

    public class OrderStatus
    {
        OrderStatus(string display) { this.display = display; }
    
        string display;
    
        public override string ToString(){ return display; }
    
        public static readonly OrderStatus AwaitingAuthorization
            = new OrderStatus("Awaiting Authorization");
        public static readonly OrderStatus InProduction
            = new OrderStatus("Item in Production");
        public static readonly OrderStatus AwaitingDispatch
            = new OrderStatus("Awaiting Dispatch");
    }
    

    You consume it the same as an enum:

    public void AuthorizeAndSendToProduction(Order order, ProductionQueue queue)
    {
        if(order.Status != OrderStatus.AwaitingAuthorization) 
        {
            Console.WriteLine("This order is not awaiting authorization!");
            return;
        }
        order.Status = OrderStatus.InProduction;
        queue.Enqueue(order);
    }
    

    The string representation is built-in, and all you need is ToString().

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

Sidebar

Related Questions

Let's say you have an enum like this: public enum ColorsEnum { Undefined, Blue,
Let's say I have a class that looks something like this: class Foo(Prop1:Int, Prop2:Int,
I have a method which takes an Enum. Say method is methodName(MyTypes) where MyTypes
Say I have an enum, public enum Colours { Red, Blue } The only
Let's say I have this enum: [Flags] enum Letters { A = 1, B
Possible Duplicate: How do I enumerate an enum? Say I have an enum type
I have a enum let's say enum MyEnum { FirstImage, SecondImage, ThirdImage, FourthImage };
Say I have a mysql table, and I have a column of type enum
Say we have deep hashes like: b = {1 => {2 => {} },
Say you have an enum that represents an error code. There will be several

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.