C# files may contain conditional code that needs to be handled by preprocessing directives during reverse engineering. A preprocessing directive is a command placed within the source code that directs the compiler to do a certain thing before the rest of the source code is parsed and compiled. The preprocessing directive has the following structure:
#directive symbol
Where # is followed by the name of the directive, and symbol is a conditional compiler constant used to select particular sections of code and exclude other sections.
In C#, symbols have no value, they can be true or false.
In the following example, the #if directive is used with symbol DEBUG to output a certain message when DEBUG symbol is true, if DEBUG symbol is false, another output message is displayed.
using System; public class MyClass { public static void Main() { #if DEBUG Console.WriteLine("DEBUG version"); #else Console.WriteLine("RELEASE version"); #endif } }
You can declare a list of symbols for preprocessing directives. These symbols are parsed by preprocessing directives: if the directive condition is true the statement is kept, otherwise the statement is removed.