diff --git a/xml/System.Diagnostics.CodeAnalysis/FeatureGuardAttribute.xml b/xml/System.Diagnostics.CodeAnalysis/FeatureGuardAttribute.xml index d5a85d51400..aa4efe29a6f 100644 --- a/xml/System.Diagnostics.CodeAnalysis/FeatureGuardAttribute.xml +++ b/xml/System.Diagnostics.CodeAnalysis/FeatureGuardAttribute.xml @@ -29,14 +29,38 @@ - Indicates that the specified public static boolean get-only property - guards access to the specified feature. + + Indicates that the specified public static Boolean read-only property + guards access to the specified feature. - Analyzers can use this to prevent warnings on calls to code that is - annotated as requiring that feature, when the callsite is guarded by a - call to the property. + + Analyzers can use this attribute to prevent warnings on calls to code that's + annotated as requiring that feature, when the callsite is guarded by a + call to the property. + + RuntimeFeature.IsDynamicCodeSupported; + + [RequiresDynamicCode("Feature requires dynamic code support.")] + internal static Implementation() => ...; // Uses dynamic code +} +``` + +When the app is built with `true`, the call to +`Feature.Implementation()` doesn't produce analyzer warning +[IL3050](/dotnet/core/deploying/native-aot/warnings/il3050) +and `Feature.Implementation` code is removed when publishing. +]]> + diff --git a/xml/System.Diagnostics.CodeAnalysis/FeatureSwitchDefinitionAttribute.xml b/xml/System.Diagnostics.CodeAnalysis/FeatureSwitchDefinitionAttribute.xml index cf8b0e4ee20..c8f6111e6c8 100644 --- a/xml/System.Diagnostics.CodeAnalysis/FeatureSwitchDefinitionAttribute.xml +++ b/xml/System.Diagnostics.CodeAnalysis/FeatureSwitchDefinitionAttribute.xml @@ -29,13 +29,40 @@ - Indicates that the specified public static boolean get-only property - corresponds to the feature switch specified by name. + + Indicates that the specified public static Boolean read-only property + corresponds to the feature switch specified by name. - IL rewriters and compilers can use this to substitute the return value - of the specified property with the value of the feature switch. + + IL rewriters and compilers can use this attribute to substitute the return value + of the specified property with the value of the feature switch. + + AppContext.TryGetSwitch("Feature.IsSupported", out bool isEnabled) ? isEnabled : true; + + internal static Implementation() => ...; +} +``` + +When the app is trimmed with the following feature settings in the project file, +`Feature.IsSupported` is treated as `false`, and `Feature.Implementation` code is removed. + +```xml + + + +``` +]]> +