Leveraging Platform-Specific APIs in .NET MAUI
“Write once, run anywhere” is a guiding principle, not an absolute rule — real apps need biometrics, sensors, secure storage, and OS-level tweaks. This deep dive compares partial classes and conditional compilation so you can add platform-specific code without turning your project into a mess.
What you’ll learn
- Why some APIs are inherently platform-bound (biometrics, file access, notifications, hardware sensors) and where forcing shared code breaks down
- How to structure partial classes and partial methods across
.shared,.android,.ios, and.windowsfiles, with fullGetDeviceName()examples - How conditional compilation (
#if ANDROID/#elif IOS/#elif WINDOWS) works and where it shines - A side-by-side comparison of both approaches on maintainability, scalability, readability, and setup cost
- A recommended hybrid pattern — partials for services and core logic,
#iffor minor inline differences — combined with dependency injection
Great guidance for turning a functional MAUI app into a production-ready one.