From maui-skills
Guides calling platform-specific native APIs in .NET MAUI apps using partial classes, conditional compilation, multi-targeting, and DI patterns for Android, iOS, Mac Catalyst, Windows.
How this skill is triggered — by the user, by Claude, or both
Slash command
/maui-skills:maui-platform-invokeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
| Scenario | Approach |
| Scenario | Approach |
|---|---|
| 1–5 lines, one-off check | #if ANDROID conditional compilation |
| Service with logic, testable | Partial classes in Platforms/ folders |
| Swappable implementations, mocking | Interface + DI registration |
Team prefers *.android.cs naming | Custom file patterns in .csproj |
Default choice: partial classes + interface + DI. Only use #if for trivial inline checks.
#if directives// ❌ Complex logic buried in #if blocks — untestable, hard to read
public async Task<bool> CheckConnectivity()
{
#if ANDROID
// 30 lines of Android networking code...
#elif IOS
// 25 lines of iOS networking code...
#endif
}
// ✅ Use partial classes — each platform file is clean and testable
// Services/ConnectivityService.cs (shared)
public partial class ConnectivityService
{
public partial Task<bool> CheckConnectivityAsync();
}
// Platforms/Android/Services/ConnectivityService.cs
public partial class ConnectivityService
{
public partial Task<bool> CheckConnectivityAsync() { /* Android impl */ }
}
All partial class files must use the same namespace, or they become separate classes.
// ❌ Different namespaces — creates TWO unrelated classes
// Services/MyService.cs
namespace MyApp.Services;
public partial class MyService { }
// Platforms/Android/MyService.cs
namespace MyApp.Platforms.Android; // WRONG!
public partial class MyService { }
// ✅ Same namespace everywhere
namespace MyApp.Services;
public partial class MyService { }
// ❌ Shared code depends on concrete platform type — can't mock in tests
public class MyViewModel
{
readonly DeviceOrientationService _service = new();
}
// ✅ Depend on interface — enables unit testing and swapping
public class MyViewModel
{
readonly IDeviceOrientationService _service;
public MyViewModel(IDeviceOrientationService service) => _service = service;
}
#else fallback// ❌ Fails compilation on unsupported platforms
public string GetDeviceName()
{
#if ANDROID
return Android.OS.Build.Model;
#elif IOS
return UIKit.UIDevice.CurrentDevice.Name;
#endif // No return for Windows or other platforms!
}
// ✅ Always include a fallback
#else
return "Unknown";
#endif
Platform.CurrentActivity is null before OnCreate completes or when the app is in the background. Always null-check or throw a clear exception.
Platforms/{Platform}/ filesFiles under Platforms/Android/ are only compiled for Android — no #if needed.
But if you put platform code in a shared folder (e.g., Services/), you must use #if or conditional <Compile> items.
If using *.android.cs naming, files won't auto-include. Add <Compile> items with platform conditions in your .csproj.
#if blocksMauiProgram.cs#if blocks include #else fallback for unsupported platformsPlatform.CurrentActivity null-checked before use (Android)<Compile> conditionsnpx claudepluginhub davidortinau/maui-skills --plugin maui-skillsBuilding .NET MAUI apps. Project structure, XAML/MVVM, platform services, current caveats.
Guards .NET MAUI projects against deprecated, obsolete, or removed APIs in XAML/C#, Blazor Hybrid, and MauiReactor. Detects target frameworks/library versions and provides replacement patterns for code generation/review/editing.
Creates and updates slim Android bindings for .NET MAUI and .NET for Android projects, guiding through Java/Kotlin wrappers, Gradle config, and Maven dependencies.