ObfuscationAttribute.Exclude Property

Definition

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

public bool Exclude { get; set; }

Property Value

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

Examples

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",
        StripAfterObfuscation=false)]
    public void MethodA() {}

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

Remarks

Важливо

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.

Applies to

Продукт Версії
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1