Enum Deletion Enterprise
The C# compiler inlines enum values at every use site, so the enum members visible to a decompiler exist mainly for reflection-based APIs like Enum.ToString(), Enum.Parse(), and Enum.IsDefined(). Demeanor removes them, so a decompiler sees empty enums with no symbolic names or values. Code that referenced the members keeps working at runtime.
Usage
| CLI | MSBuild | Default |
|---|---|---|
| (enabled by default at Enterprise) | (enabled by default at Enterprise) | On |
--no-enum-deletion | <DemeanorNoEnumDeletion>true</DemeanorNoEnumDeletion> | Disable |
Before & After
public enum DiscountType
{
None = 0,
Percentage = 1,
FixedAmount = 2,
BuyOneGetOne = 3,
Seasonal = 4,
Employee = 5,
}
public enum TaxRegion
{
None = 0,
US = 1,
EU = 2,
UK = 3,
Japan = 4,
}public enum g
{
}
public enum h
{
}Real ILSpy output. Both enums are empty — all 11 members removed. Code that used DiscountType.Percentage still works at runtime because the compiler inlined the value at every use site. Enum.ToString() returns the integer value ("1") instead of the symbolic name ("Percentage").
Effect on Decompiled Code
Before deletion, a decompiler shows DiscountType.BuyOneGetOne. After deletion, it shows (g)3 — a cast of the raw integer to the now-empty enum type. Switch statements that used symbolic names become numeric:
// Before: meaningful switch
case DiscountType.BuyOneGetOne:
num = _basePrice / 2m;
// After: raw integers
case (g)3:
num = this.m_a / 2m; When to Disable
Enum.ToString()— if your application displays enum member names to users (e.g., in logs or UI), those will show raw integers after deletion. Exclude specific enums with[Obfuscation(Exclude = true)].Enum.Parse()/Enum.IsDefined()— parsing enum values from configuration files or user input by name will fail.- Serialization — JSON serializers that write enum names (not values) will produce integers. Most serializers default to numeric values, which still work.
Ready to protect your .NET code?