Skip to main content
Version: 2023.3

5.5. Custom Attributes Removal

.NET provides a set of custom attributes that allows to describe meta properties of a given class, field, property or method.

For example, Windows Forms and WPF visual designers use System.ComponentModel.DescriptionAttribute to find the textual descriptions for editable class properties. There are other use cases and they are numerous.

Eazfuscator.NET automatically prunes excessive meta attributes whenever possible. However you may prefer to remove all custom attributes with given conditions in some scenarios to achieve better obfuscation coverage.

Instructions on using the custom attributes removal

Suppose we want to remove System.ComponentModel.DescriptionAttribute from every class member of the assembly. Please follow the instructions below to achieve that.

  1. Open obfuscatable project inside the IDE

  2. Add new source file to the project and call it ObfuscationSettings.cs (for C#) or ObfuscationSettings.vb (for Visual Basic .NET). You may prefer to use another name instead of ObfuscationSettings.cs or ObfuscationSettings.vb

  3. Fill ObfuscationSettings.cs with the following content (C#):

    using System;
    using System.Reflection;

    [assembly: Obfuscation(Feature = "apply to type *: apply to member *: remove custom attribute System.ComponentModel.DescriptionAttribute", Exclude = false)]

    For Visual Basic .NET, fill ObfuscationSettings.vb with the following content:

    Imports System
    Imports System.Reflection

    <Assembly: Obfuscation(Feature:="apply to type *: apply to member *: remove custom attribute System.ComponentModel.DescriptionAttribute", Exclude:=False)>
Tip

You can use specific conditions to define the scope of custom attributes removal. See conditional obfuscation for details.

Tip

You can specify any class name instead of System.ComponentModel.DescriptionAttribute.
Patterns are allowed too, for example: *.DescriptionAttribute

Tip

Attribute literal at the end of the class name can be omitted, e.g. System.ComponentModel.Description will do the job too.