Detect when WPF/WInForm/Android runtime is included in a project

Viewed 19

I have an Extension class I share within multiple projects where the project can be Android (Xamarin/.NET MAUI) but also a WinForm/WPF app or even a WinForm one with some WPF windows and I'm wondering if there are existing preprocessor macros to enable or disable some code, e.g. 'System.Data.SqlClient' stuff is not available on Android and 'System.Windows' (which I have some extensions) is not part of a WinForm project unless some dll are manually referenced (such PresentationCore, PresentationFramework, WindowsBase, WindowsFormsIntegration etc.). So my question is: is there any preprocessor macro to enable/disable code for Android, WPF and WinForm at compile time?

what i would is something like:

#if !(ANDROID_RUNTIME)
public static string SqlDataReaderStringExt(this SqlDataReader reader, int i) 
{
    ...
}
#endif

#if WPF_RUNTIME
....
#endif

#if WINFORM_RUNTIME
....
#endif

so, stop manually comment the code in each project.

0 Answers
Related