Search code examples
c#confuserex

How i exclude part of code being obfuscated by ConfuserEx?


Im looking to how i can exclude a line of code in my project, but all i found is how to exclude a complete namespace, can you help me ?


Solution

  • .NET has an attribute called ObfuscationAttribute, which has an Exclude property.

    The documentation for Exclude says:

    Gets or sets a Boolean value indicating whether the obfuscation tool should exclude the type or member from obfuscation.

    You should be able to add [Obfuscation(Exclude = true)] to the member(s) you want to exclude. If the obfuscator tool you're using properly respect this attribute (ConfuserEx should be respecting this AFAIK), it should get the work done.

    Example:

    [Obfuscation(Exclude = true)]
    public class MyClass
    {
        [Obfuscation(Exclude = true)] 
        public enum MyEnum
        {
            Value1,
            Value2,
        }
    
        [Obfuscation(Exclude = true)]    
        public void MyFunction(MyEnum e_Enum)
        {
        }
    }