Compiling code based on the target platform
.NET offers a powerful mechanism that lets you compile code based on specific conditions and parameters. This feature is known as preprocessor directives, and more specifically, conditional compilation directives.
Preprocessor directives
Preprocessor directives are instructions processed by the compiler before the actual compilation of the code begins.
Preprocessor directives have a wide range of applications, and we’re focusing on them here because they enable us to include specific code sections in the compilation process based on the target platform.
In this recipe, we’ll create a simple example that displays the current platform name on a label. However, platform-based compilation is a versatile tool that can be utilized in various scenarios, such as the following:
- Calling platform APIs: Access APIs that are available only on specific platforms, for instance, getting the custom accent color that is available...