Attributes
The Obfuscator includes several code-based Attributes that can be applied to your classes, methods, fields, and more to manage 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 its contents from being obfuscated. However, method bodies (including string obfuscation and random code generation) will still be obfuscated. To avoid obfuscating method bodies as well, add the DoNotObfuscateMethodBody-Attribute to the class or 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 obfuscation of all method bodies, or to a specific method to exclude its body from obfuscation. This includes string obfuscation and random code generation as part of the 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 the addition of fake / random code or 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 class members to force obfuscation with a new name, even if the settings would normally prevent it. This is useful if 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 .NET built-in Obfuscation-Attribute.
The System.Diagnostics.ObfuscationAttribute class is used to specify that an assembly, type, or member should not be obfuscated by an obfuscation tool, allowing specific parts of the code to remain visible and accessible even after obfuscation. This attribute is typically used to prevent obfuscation of types or members that are required to be 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();
...
}