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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:13:10+00:00 2026-05-11T04:13:10+00:00

I have this enum: [Flags] public enum ExportFormat { None = 0, Csv =

  • 0

I have this enum:

[Flags] public enum ExportFormat {     None = 0,     Csv = 1,     Tsv = 2,     Excel = 4,     All = Excel | Csv | Tsv } 

I am trying to make a wrapper on this (or any, really) enum which notifies on change. Currently it looks like this:

public class NotifyingEnum<T> : INotifyPropertyChanged     where T : struct {     private T value;      public event PropertyChangedEventHandler PropertyChanged;      public NotifyingEnum()     {         if (!typeof (T).IsEnum)             throw new ArgumentException('Type T must be an Enum');     }      public T Value     {         get { return value; }         set         {             if (!Enum.IsDefined(typeof (T), value))                 throw new ArgumentOutOfRangeException('value', value, 'Value not defined in enum, ' + typeof (T).Name);              if (!this.value.Equals(value))             {                 this.value = value;                  PropertyChangedEventHandler handler = PropertyChanged;                 if (handler != null)                     handler(this, new PropertyChangedEventArgs('Value'));             }         }     } } 

Since an enum can be assigned with any value really, I want to check if the given Value is defined. But I found a problem. If I here give it an enum consisting of for example Csv | Excel, then Enum.IsDefined will return false. Apparently because I haven’t defined any enum consisting of those two. I guess that on some level is logical, but how should I then check if the given value is valid? In other words, to make it work, what do I need to swap this following line with?

if (!Enum.IsDefined(typeof (T), value)) 
  • 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. 2026-05-11T04:13:11+00:00Added an answer on May 11, 2026 at 4:13 am

    With flag-based enums, it’s about having a bit set or not. So for ‘ExportFormat’, if bit 1 is set, it’s CSV format, even though there might be more bits set. Is having bit 1 and 2 set an invalid value? This is subjective: from the point of view of the values as a group, it is invalid (there’s no bitpattern defined for bits 1 and 2 set) however, as each value is a bit, looking at them individually, it can be that a value with bits 1 and 2 set is valid.

    If one passes in the value 0011111011, is that a valid value? Well, it depends on what you’re looking for: if you are looking at the whole value, then it’s an invalid value, but if you’re looking at individual bits, it’s an ok value: it has bits set which aren’t defined, but that’s ok, as flag-based enums are checked ‘per bit’: you’re not comparing them to a value, you’re checking whether a bit is set or not.

    So, as your logic will check on which bits are set to select which formats to pick, it’s realy not necessary to check whether the enum value is defined: you have 3 formats: if the bit of the corresponding format is set, the format is selected. That’s the logic you should write.

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" ContentType="text/xml" %> May 11, 2026 at 7:52 pm
  • Editorial Team
    Editorial Team added an answer To be honest only bother if you are actually going… May 11, 2026 at 7:52 pm
  • Editorial Team
    Editorial Team added an answer All of these suggestions are at the XSL-FO level, which… May 11, 2026 at 7:52 pm

Related Questions

I have a FormView (bound to an ObjectDataSource) that contains a CheckBoxList that I'd
I was going to ask a question here about whether or not my design
I am creating a Windows service. When an exception occurrs, I handle it appropriately
I've attempted to create an abstracted control to manage some of the state in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.