ObfuscationAttribute.Exclude Property


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

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public bool Exclude { get; set; }

Property Value

Type: System.Boolean

true if the type or member to which this attribute is applied should be excluded from obfuscation; otherwise, false. The default is true.


Applying this attribute does not automatically obfuscate the code entity to which you apply it. Applying the attribute is an alternative to creating a configuration file for the obfuscation tool. That is, it merely provides instructions for an obfuscation tool. Microsoft recommends that vendors of obfuscation tools follow the semantics described here. However, there is no guarantee that a particular tool follows Microsoft recommendations.

The following code example shows a type that is marked to be excluded from obfuscation. It is not necessary to specify the Exclude property, because it defaults to true, but specifying it explicitly makes your intent clear. The ApplyToMembers is set to false, so that the exclusion from obfuscation does not apply to the members of the class. That is, the class name is visible but the members are obfuscated.

The MethodA method is marked with the value "default" for the Feature property. It is necessary to specify false for the Exclude property in order to avoid excluding MethodA from obfuscation, because the default for the Exclude property is true. The StripAfterObfuscation property is false so that the obfuscation tool will not strip the attribute after obfuscation.

This code is part of a larger example that can be compiled and executed. See the ObfuscationAttribute class.

[ObfuscationAttribute(Exclude=true, ApplyToMembers=false)]
public class Type2

    // The exclusion of the type is not applied to its members,
    // however in order to mark the member with the "default" 
    // feature it is necessary to specify Exclude=false,
    // because the default value of Exclude is true. The tool
    // should not strip this attribute after obfuscation.
    [ObfuscationAttribute(Exclude=false, Feature="default", 
    public void MethodA() {}

    // This member is marked for obfuscation, because the 
    // exclusion of the type is not applied to its members.
    public void MethodB() {}


.NET Framework
Available since 2.0
Return to top