@@ -14,20 +14,21 @@ namespace Microsoft.Maui
1414 /// </remarks>
1515 internal static class RuntimeFeature
1616 {
17- private const bool IsIVisualAssemblyScanningEnabledByDefault = false ;
18- private const bool IsShellSearchResultsRendererDisplayMemberNameSupportedByDefault = true ;
19- private const bool IsQueryPropertyAttributeSupportedByDefault = true ;
20- private const bool IsImplicitCastOperatorsUsageViaReflectionSupportedByDefault = true ;
21- private const bool AreBindingInterceptorsSupportedByDefault = true ;
22- private const bool IsXamlCBindingWithSourceCompilationEnabledByDefault = false ;
23- private const bool IsHybridWebViewSupportedByDefault = true ;
17+ const bool IsIVisualAssemblyScanningEnabledByDefault = false ;
18+ const bool IsShellSearchResultsRendererDisplayMemberNameSupportedByDefault = true ;
19+ const bool IsQueryPropertyAttributeSupportedByDefault = true ;
20+ const bool IsImplicitCastOperatorsUsageViaReflectionSupportedByDefault = true ;
21+ const bool AreBindingInterceptorsSupportedByDefault = true ;
22+ const bool IsXamlCBindingWithSourceCompilationEnabledByDefault = false ;
23+ const bool IsHybridWebViewSupportedByDefault = true ;
24+ const bool EnableDiagnosticsByDefault = false ;
2425
2526#pragma warning disable IL4000 // Return value does not match FeatureGuardAttribute 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute'.
2627#if NET9_0_OR_GREATER
2728 [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.IsIVisualAssemblyScanningEnabled" ) ]
2829 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
2930#endif
30- internal static bool IsIVisualAssemblyScanningEnabled =>
31+ public static bool IsIVisualAssemblyScanningEnabled =>
3132 AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.IsIVisualAssemblyScanningEnabled" , out bool isEnabled )
3233 ? isEnabled
3334 : IsIVisualAssemblyScanningEnabledByDefault ;
@@ -36,7 +37,7 @@ internal static class RuntimeFeature
3637 [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.IsShellSearchResultsRendererDisplayMemberNameSupported" ) ]
3738 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
3839#endif
39- internal static bool IsShellSearchResultsRendererDisplayMemberNameSupported
40+ public static bool IsShellSearchResultsRendererDisplayMemberNameSupported
4041 => AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.IsShellSearchResultsRendererDisplayMemberNameSupported" , out bool isSupported )
4142 ? isSupported
4243 : IsShellSearchResultsRendererDisplayMemberNameSupportedByDefault ;
@@ -45,7 +46,7 @@ internal static bool IsShellSearchResultsRendererDisplayMemberNameSupported
4546 [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.IsQueryPropertyAttributeSupported" ) ]
4647 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
4748#endif
48- internal static bool IsQueryPropertyAttributeSupported =>
49+ public static bool IsQueryPropertyAttributeSupported =>
4950 AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.IsQueryPropertyAttributeSupported" , out bool isSupported )
5051 ? isSupported
5152 : IsQueryPropertyAttributeSupportedByDefault ;
@@ -54,23 +55,23 @@ internal static bool IsShellSearchResultsRendererDisplayMemberNameSupported
5455 [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.IsImplicitCastOperatorsUsageViaReflectionSupported" ) ]
5556 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
5657#endif
57- internal static bool IsImplicitCastOperatorsUsageViaReflectionSupported =>
58+ public static bool IsImplicitCastOperatorsUsageViaReflectionSupported =>
5859 AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.IsImplicitCastOperatorsUsageViaReflectionSupported" , out bool isSupported )
5960 ? isSupported
6061 : IsImplicitCastOperatorsUsageViaReflectionSupportedByDefault ;
6162
6263#if NET9_0_OR_GREATER
6364 [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.Microsoft.Maui.RuntimeFeature.AreBindingInterceptorsSupported" ) ]
6465#endif
65- internal static bool AreBindingInterceptorsSupported =>
66+ public static bool AreBindingInterceptorsSupported =>
6667 AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.AreBindingInterceptorsSupported" , out bool areSupported )
6768 ? areSupported
6869 : AreBindingInterceptorsSupportedByDefault ;
6970
7071#if NET9_0_OR_GREATER
7172 [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.IsXamlCBindingWithSourceCompilationEnabled" ) ]
7273#endif
73- internal static bool IsXamlCBindingWithSourceCompilationEnabled =>
74+ public static bool IsXamlCBindingWithSourceCompilationEnabled =>
7475 AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.IsXamlCBindingWithSourceCompilationEnabled" , out bool areSupported )
7576 ? areSupported
7677 : IsXamlCBindingWithSourceCompilationEnabledByDefault ;
@@ -80,10 +81,29 @@ internal static bool IsShellSearchResultsRendererDisplayMemberNameSupported
8081 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
8182 [ FeatureGuard ( typeof ( RequiresDynamicCodeAttribute ) ) ]
8283#endif
83- internal static bool IsHybridWebViewSupported =>
84+ public static bool IsHybridWebViewSupported =>
8485 AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.IsHybridWebViewSupported" , out bool isSupported )
8586 ? isSupported
8687 : IsHybridWebViewSupportedByDefault ;
88+
89+ #if NET9_0_OR_GREATER
90+ [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.EnableDiagnostics" ) ]
91+ #endif
92+ public static bool EnableDiagnostics
93+ {
94+ get
95+ {
96+ return AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.EnableDiagnostics" , out bool isEnabled )
97+ ? isEnabled
98+ : EnableDiagnosticsByDefault ;
99+ }
100+ internal set
101+ {
102+ // This property is internal settable to allow tests to enable diagnostics.
103+ // It should not be set in production code.
104+ AppContext . SetSwitch ( "Microsoft.Maui.RuntimeFeature.EnableDiagnostics" , value ) ;
105+ }
106+ }
87107#pragma warning restore IL4000
88108 }
89109}
0 commit comments