Eazfuscator.NET breaks Enum.IsDefined

In my code, I use a lot of small enumerations:

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

I often have to check for integer input before converting it to this enumeration.

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

This approach does not work when the enumeration uses the FlagsAttribute flag; Enum.IsDefined cannot automatically combine flags to create the specified value. However, I managed to get around without requiring FlagsAttribute.

However, TIL that Eazfuscator.NET obfuscation breaks Enum.IsDefined. I knew this was an opportunity, but I was hoping this would not happen, since it is not in the System.Reflection namespace (although it is reportedly using System.Reflection heavily).

So I wonder if anyone has any good alternatives. I specifically after the following:

  • Checks if an integer is in the specified enumeration.
  • Compatible with .NET Framework 2.0 and Mono Framework.
  • Causes obfuscation without explicitly disabling it (using attributes or any GUI tool).
+3
source share
1 answer

In case others run into this problem and find this article, the solution I went with was to add an extra member of the listing to each of my listings.

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

This is a practice that I remember using in C ((not ANSI) C # defines) to iterate over enumeration values, its only drawback is that it is difficult to maintain.

, (, ); MAXVAL, , . , , .

public static bool TryParseByteToEnum<T>(byte input_byte, 
    out T enum_member, T max_value) where 
        T : struct, IConvertible
+2

All Articles