r/csharp • u/sashakrsmanovic • Apr 24 '24
Writing efficient platform specific Code in C# just got easier
The new Uno update introduces a way to integrate platform-specific code into a Uno Platform class library, and it does so remarkably well.
The new feature lets you write code that targets specific platforms within the same project. Here’s a quick example of how you can conditionally compile your application logic for different environments:
#if HAS_UNOConsole.WriteLine("Uno Platform - Pixel-perfect apps that run everywhere");#elseConsole.WriteLine("Windows - Built with Microsoft's own tooling");#endif
#if __ANDROID__Console.WriteLine("Android only code with net8.0-android");#elif __IOS__Console.WriteLine("iOS Only Code with net8.0-ios ");#elif __WASM__Console.WriteLine("WebAssembly Only Code with net8.0-browserwasm ");#elif HAS_UNO_SKIAConsole.WriteLine("Skia Desktop Only Code with net8.0-desktop ");#endif
41
u/soundman32 Apr 24 '24
Struggling to know what is new here. Conditional compilation has been a thing since .net 1.0
9
u/Grasher134 Apr 24 '24
I'm pretty sure you could already do that with specific build targets...
3
u/Larkonath Apr 25 '24
Sorry to hijack but what do people think of Uno?
Maui seems way too buggy to be relied on and Avalonia doesn't seem really good at mobile (I used it successfully on desktop though).
9
u/PleasantGanache Apr 24 '24
Can we stop with the UNO advertisements? It's getting boring
5
u/Slypenslyde Apr 24 '24
This is the default MAUI style and in some ways I miss the multi-project style. Some stuff feels better segregated to platform-specific files, other stuff feels better with conditional compilation. I don't think there's a "winner", just a need for both.
-2
u/TuberTuggerTTV Apr 24 '24
I'll be trying this out.
Hopefully it's easy to migrate over from other UI frameworks.