#nullable enable using System; using Avalonia.Metadata; using Avalonia.Platform; namespace Avalonia.Markup.Xaml.MarkupExtensions; public sealed class OnFormFactorExtension : OnFormFactorExtensionBase { public OnFormFactorExtension() { } public OnFormFactorExtension(object defaultValue) { Default = defaultValue; } public static bool ShouldProvideOption(IServiceProvider serviceProvider, FormFactorType option) { return serviceProvider.GetService().GetRuntimeInfo().FormFactor == option; } } public sealed class OnFormFactorExtension : OnFormFactorExtensionBase> { public OnFormFactorExtension() { } public OnFormFactorExtension(TReturn defaultValue) { Default = defaultValue; } public static bool ShouldProvideOption(IServiceProvider serviceProvider, FormFactorType option) { return serviceProvider.GetService().GetRuntimeInfo().FormFactor == option; } } public abstract class OnFormFactorExtensionBase : IAddChild where TOn : On { [MarkupExtensionDefaultOption] public TReturn? Default { get; set; } [MarkupExtensionOption(FormFactorType.Desktop)] public TReturn? Desktop { get; set; } [MarkupExtensionOption(FormFactorType.Mobile)] public TReturn? Mobile { get; set; } // Required for the compiler, will be replaced with actual method compile time. public object ProvideValue() { return this; } void IAddChild.AddChild(TOn child) {} }