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 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 text file with some stuff that i would like to put into
Have done some research and found some stuff that may be helpful. I would
I have an app that creates a database and do some stuff. I am
I have a stored procedure that does, among other stuff, some inserts in different
This is uni assignment and I have already done some stuff. Please go to
Consider this scenario. I have some business logic that now and then will be
I have a class Foo that uses another class Bar to do some stuff.
--EDIT-- I believe this is a valid question that may have multiple answers (as
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

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.