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

  • Home
  • SEARCH
  • 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 265703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:47:34+00:00 2026-05-11T22:47:34+00:00

We have some stuff that may be exported into various formats. Currently we have

  • 0

We have some stuff that may be exported into various formats. Currently we have these formats represented by an enum like this:

[Flags]
public enum ExportFormat
{
    None = 0x0,
    Csv = 0x1,
    Tsv = 0x2,
    Excel = 0x4,
    All = Excel | Csv | Tsv
}

Problem is that these must be enumerated and they also need a translation or description in the ui. Currently I solved this by creating two extension methods. They work, but I don’t really like them or the solution at all… they feel kind of smelly. Problem is I don’t really know how I could do this better. Does anyone have any good alternatives? These are the two methods:

    public static IEnumerable<ExportFormat> Formats(this ExportFormat exportFormats)
    {
        foreach (ExportFormat e in Enum.GetValues(typeof (ExportFormat)))
        {
            if (e == ExportFormat.None || e == ExportFormat.All)
                continue;

            if ((exportFormats & e) == e)
                yield return e;
        }
    }

    public static string Describe(this ExportFormat e)
    {
        var r = new List<string>();

        if ((e & ExportFormat.Csv) == ExportFormat.Csv)
            r.Add("Comma Separated Values");

        if ((e & ExportFormat.Tsv) == ExportFormat.Tsv)
            r.Add("Tab Separated Values");

        if ((e & ExportFormat.Excel) == ExportFormat.Excel)
            r.Add("Microsoft Excel 2007");

        return r.Join(", ");
    }

Maybe this is the way to do this, but I have a feeling there must be better ways to do it. How could I refactor 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-11T22:47:35+00:00Added an answer on May 11, 2026 at 10:47 pm

    You could use the Formats method inside Describe to avoid doing all the bit operations at multiple places, like this:

    private static Dictionary<ExportFormat, string> FormatDescriptions =
        new Dictionary<ExportFormat,string>()
    {
        { ExportFormat.Csv, "Comma Separated Values" },
        { ExportFormat.Tsv, "Tab Separated Values" },
        { ExportFormat.Excel, "Microsoft Excel 2007" },            
    };
    
    public static string Describe(this ExportFormat e)
    {
        var formats = e.Formats();
        var descriptions = formats.Select(fmt => FormatDescriptions[fmt]);
    
        return string.Join(", ", descriptions.ToArray());
    }
    

    This way, it is easy to incorporate the string descriptions from an external source or localization, as hinted above.

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

Sidebar

Related Questions

I have some stuff in settings.py that I'd like to be able to access
I have a class that after it does some stuff, sends a JMS message.
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
Consider this scenario. I have some business logic that now and then will be
Found this which may explain some of my problems - MSDN Post I have
Suppose I have some text files (f1.txt, f2.txt, ...) that looks something like @article
First of all I must say that this may seem like a lot of
As everyone knows, sometimes developers have to document stuff. Or capture some stuff for
I have some UI in VB 2005 that looks great in XP Style, but

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.