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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:01:54+00:00 2026-06-02T21:01:54+00:00

In my code I make use of many small enums: enum UserRequest : byte

  • 0

In my code I make use of many small enums:

enum UserRequest : byte { Burp=1, Sneeze=2, Fart=3 }

I often need to validate integer input before converting it to this enum.

bool valid_input = Enum.IsDefined(typeof(UserRequest), user_byte_value);

This approach does not work when the enum makes use of the FlagsAttribute; Enum.IsDefined cannot automatically combine flags to make a specified value. However, I’ve been able to work around not needing FlagsAttribute.

However, TIL that Eazfuscator.NET‘s obfuscation breaks Enum.IsDefined. I knew it was a possibility, but I was hoping it wouldn’t since it’s not in the System.Reflection namespace (reportedly though, it makes heavy use of System.Reflection).

So I’m wondering if anyone knows any good alternatives. I’m specifically after the following:

  1. Allows checking if an integer is in a specified enum.
  2. Compatible with .NET Framework 2.0 and the Mono Framework.
  3. Survives obfuscation without explicitly disabling it (using attributes or some GUI tool).
  • 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-02T21:01:55+00:00Added an answer on June 2, 2026 at 9:01 pm

    In the event others run into this same problem, and find this article, the solution I went with was to add an additional enum member to each of my enums.

    enum UserRequests : byte
    {
        Burp = 0,
        Sneeze = 1,
        Fart = 2,
        /* Maximum Valid Value */
        MAXVAL = Fart
    }
    

    This is a practice I remember using in C ((non-ANSI) with #defines) to iterate over enum values, its only downside is that it’s hard to maintain.

    I wrote a generic function to lesson the burden (header shown below); I still have to explicitly pass the MAXVAL member, but it’s less work than I thought. And of course, it survives obfuscation and is portable.

    public static bool TryParseByteToEnum<T>(byte input_byte, 
        out T enum_member, T max_value) where 
            T : struct, IConvertible
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the following code to make an image fadeOut and, only
I use a wrapper around make to compile C++ code within a project. For
When I use the form helper to make a time input,usaually I write code
I make call from my app with this code (i use webview because after
I've been trying to make GNU gdb 6.5-14 to use the source code embedded
I use PhpStorm. I want to make snippets of code and then assign shortcuts
i use this code to split a data to make a list with three
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I need help trying to process many small files. I need to remove the
I know the code to make an image grow in size is: imageView.transform =

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.