@@ -14,6 +14,8 @@ namespace Microsoft.Maui
1414 /// </remarks>
1515 internal static class RuntimeFeature
1616 {
17+ const string FeatureSwitchPrefix = "Microsoft.Maui.RuntimeFeature." ;
18+
1719 const bool IsIVisualAssemblyScanningEnabledByDefault = false ;
1820 const bool IsShellSearchResultsRendererDisplayMemberNameSupportedByDefault = true ;
1921 const bool IsQueryPropertyAttributeSupportedByDefault = true ;
@@ -25,83 +27,91 @@ internal static class RuntimeFeature
2527
2628#pragma warning disable IL4000 // Return value does not match FeatureGuardAttribute 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute'.
2729#if NET9_0_OR_GREATER
28- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature. IsIVisualAssemblyScanningEnabled") ]
30+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( IsIVisualAssemblyScanningEnabled ) } ") ]
2931 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
3032#endif
3133 public static bool IsIVisualAssemblyScanningEnabled =>
32- AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. IsIVisualAssemblyScanningEnabled", out bool isEnabled )
34+ AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( IsIVisualAssemblyScanningEnabled ) } ", out bool isEnabled )
3335 ? isEnabled
3436 : IsIVisualAssemblyScanningEnabledByDefault ;
3537
3638#if NET9_0_OR_GREATER
37- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature. IsShellSearchResultsRendererDisplayMemberNameSupported") ]
39+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( IsShellSearchResultsRendererDisplayMemberNameSupported ) } ") ]
3840 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
3941#endif
4042 public static bool IsShellSearchResultsRendererDisplayMemberNameSupported
41- => AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. IsShellSearchResultsRendererDisplayMemberNameSupported", out bool isSupported )
43+ => AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( IsShellSearchResultsRendererDisplayMemberNameSupported ) } ", out bool isSupported )
4244 ? isSupported
4345 : IsShellSearchResultsRendererDisplayMemberNameSupportedByDefault ;
4446
4547#if NET9_0_OR_GREATER
46- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature. IsQueryPropertyAttributeSupported") ]
48+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( IsQueryPropertyAttributeSupported ) } ") ]
4749 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
4850#endif
4951 public static bool IsQueryPropertyAttributeSupported =>
50- AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. IsQueryPropertyAttributeSupported", out bool isSupported )
52+ AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( IsQueryPropertyAttributeSupported ) } ", out bool isSupported )
5153 ? isSupported
5254 : IsQueryPropertyAttributeSupportedByDefault ;
5355
5456#if NET9_0_OR_GREATER
55- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature. IsImplicitCastOperatorsUsageViaReflectionSupported") ]
57+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( IsImplicitCastOperatorsUsageViaReflectionSupported ) } ") ]
5658 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
5759#endif
5860 public static bool IsImplicitCastOperatorsUsageViaReflectionSupported =>
59- AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. IsImplicitCastOperatorsUsageViaReflectionSupported", out bool isSupported )
61+ AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( IsImplicitCastOperatorsUsageViaReflectionSupported ) } ", out bool isSupported )
6062 ? isSupported
6163 : IsImplicitCastOperatorsUsageViaReflectionSupportedByDefault ;
6264
6365#if NET9_0_OR_GREATER
64- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.Microsoft.Maui.RuntimeFeature. AreBindingInterceptorsSupported") ]
66+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( AreBindingInterceptorsSupported ) } ") ]
6567#endif
6668 public static bool AreBindingInterceptorsSupported =>
67- AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. AreBindingInterceptorsSupported", out bool areSupported )
69+ AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( AreBindingInterceptorsSupported ) } ", out bool areSupported )
6870 ? areSupported
6971 : AreBindingInterceptorsSupportedByDefault ;
7072
7173#if NET9_0_OR_GREATER
72- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature. IsXamlCBindingWithSourceCompilationEnabled") ]
74+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( IsXamlCBindingWithSourceCompilationEnabled ) } ") ]
7375#endif
7476 public static bool IsXamlCBindingWithSourceCompilationEnabled =>
75- AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. IsXamlCBindingWithSourceCompilationEnabled", out bool areSupported )
77+ AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( IsXamlCBindingWithSourceCompilationEnabled ) } ", out bool areSupported )
7678 ? areSupported
7779 : IsXamlCBindingWithSourceCompilationEnabledByDefault ;
7880
7981#if NET9_0_OR_GREATER
80- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature. IsHybridWebViewSupported") ]
82+ [ FeatureSwitchDefinition ( $ " { FeatureSwitchPrefix } . { nameof ( IsHybridWebViewSupported ) } ") ]
8183 [ FeatureGuard ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
8284 [ FeatureGuard ( typeof ( RequiresDynamicCodeAttribute ) ) ]
8385#endif
8486 public static bool IsHybridWebViewSupported =>
85- AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature. IsHybridWebViewSupported", out bool isSupported )
87+ AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( IsHybridWebViewSupported ) } ", out bool isSupported )
8688 ? isSupported
8789 : IsHybridWebViewSupportedByDefault ;
8890
8991#if NET9_0_OR_GREATER
90- [ FeatureSwitchDefinition ( "Microsoft.Maui.RuntimeFeature.EnableDiagnostics" ) ]
92+ [ FeatureSwitchDefinition ( $ "{ FeatureSwitchPrefix } .{ nameof ( EnableDiagnostics ) } ") ]
93+ #endif
94+ public static bool EnableDiagnostics => AppContext . TryGetSwitch ( $ "{ FeatureSwitchPrefix } .{ nameof ( EnableDiagnostics ) } ", out bool isEnabled )
95+ ? isEnabled
96+ : EnableDiagnosticsByDefault ;
97+
98+
99+ #if NET9_0_OR_GREATER
100+ [ FeatureSwitchDefinition ( $ "{ FeatureSwitchPrefix } .{ nameof ( EnableMauiDiagnostics ) } ") ]
91101#endif
92- public static bool EnableDiagnostics
102+ public static bool EnableMauiDiagnostics
93103 {
94104 get
95105 {
96- return AppContext . TryGetSwitch ( "Microsoft.Maui.RuntimeFeature.EnableDiagnostics ", out bool isEnabled )
106+ return AppContext . TryGetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( EnableMauiDiagnostics ) } ", out bool isEnabled )
97107 ? isEnabled
98- : EnableDiagnosticsByDefault ;
108+ : EnableDiagnostics ;
99109 }
100110 internal set
101111 {
102112 // This property is internal settable to allow tests to enable diagnostics.
103113 // It should not be set in production code.
104- AppContext . SetSwitch ( "Microsoft.Maui.RuntimeFeature.EnableDiagnostics ", value ) ;
114+ AppContext . SetSwitch ( $ " { FeatureSwitchPrefix } . { nameof ( EnableMauiDiagnostics ) } ", value ) ;
105115 }
106116 }
107117#pragma warning restore IL4000
0 commit comments