Attributes
The Obfuscator includes several code-based Attributes that you can apply to your classes, methods, fields, and other members to fine-tune the obfuscation.
DoNotRenameAttribute
Apply this attribute to a class, field, method, or any other member to prevent its name from being renamed (obfuscated).
// Skip the obfuscation of the namespace and class name.
[DoNotRenameAttribute]
public class Foo
{
// Skip the obfuscation of the method name. Also affects virtual, abstract, override methods.
[DoNotRenameAttribute]
public void Bar();
...
}
DoNotObfuscateClassAttribute
Use this attribute on a class to prevent the entire class and all of its contents from being renamed. Note that method bodies (including string obfuscation and random code generation) will still be obfuscated. To skip method body obfuscation as well, add the DoNotObfuscateMethodBody attribute to the class or to specific methods.
// Skip the obfuscation of the whole class and its members. Also affects virtual, abstract, override methods.
[DoNotObfuscateClassAttribute]
public class Foo
{
public void Bar();
...
}
DoNotObfuscateMethodBodyAttribute
Apply this attribute to a class to skip body obfuscation for all of its methods, or to a single method to exclude only its body from obfuscation. This also covers string obfuscation and random code generation, which are part of method body obfuscation.
// Skip the body obfuscation of all methods inside the class.
[DoNotObfuscateMethodBodyAttribute]
public class Foo
{
// Skip the body obfuscation of this method.
[DoNotObfuscateMethodBodyAttribute]
public void Bar()
{
var myString = "Hello World!";
}
...
}
DoNotUseClassForFakeCodeAttribute
Use this attribute on a class to prevent fake / random code from being added to it, and to disallow the creation of new fake classes based on it.
// Do not add random code into this class or generate random classes based on this class.
[DoNotUseClassForFakeCodeAttribute]
public class Foo
{
public void Bar();
...
}
ObfuscateAnywayAttribute
Apply this attribute to a class or member to force obfuscation with a custom new name, even when the settings would normally prevent it. This is useful when you want to obfuscate specific public methods while leaving others untouched.
// Even if obfuscation got deactivated for this class, you can force obfuscation with a custom name.
[ObfuscateAnywayAttribute("AwesomeClassName")]
public class Foo
{
// Even if obfuscation got deactivated for this method, you can force obfuscation with a custom name.
[ObfuscateAnywayAttribute("AwesomeMethodName")]
public void Bar();
...
}
ObfuscationAttribute
The Obfuscator also supports the built-in .NET Obfuscation attribute.
The System.Diagnostics.ObfuscationAttribute class lets you specify that an assembly, type, or member should not be obfuscated, allowing specific parts of the code to remain visible and accessible even after obfuscation. It is typically used to protect types or members that need to remain publicly visible, such as those used in COM interoperability or reflection.
// Exclude the class Foo from obfuscation.
[ObfuscationAttribute(Exclude=true)]
public class Foo
{
// Exclude the method Bar from obfuscation.
[ObfuscationAttribute(Exclude=true)]
public void Bar();
...
}
NotObfuscatedCauseAttribute
This attribute is used internally by the Obfuscator in development builds. It marks code with the reason why a name was not obfuscated.
You normally should not add this attribute yourself. It is mainly useful for debugging and support, because it helps explain why a class, method, field, property, or event kept its original name.
If support asks for this information, make a development build and send the Obfuscator log together with your issue report.