File tree Expand file tree Collapse file tree 2 files changed +60
-9
lines changed
xml/System.Diagnostics.CodeAnalysis Expand file tree Collapse file tree 2 files changed +60
-9
lines changed Original file line number Diff line number Diff line change 29
29
</Attributes >
30
30
<Docs >
31
31
<summary >
32
- <para >Indicates that the specified public static boolean get-only property</para >
33
- <para >guards access to the specified feature.</para >
32
+ <para >
33
+ Indicates that the specified public static Boolean read-only property
34
+ guards access to the specified feature.</para >
34
35
</summary >
35
36
<remarks >
36
- <para >Analyzers can use this to prevent warnings on calls to code that is</para >
37
- <para >annotated as requiring that feature, when the callsite is guarded by a</para >
38
- <para >call to the property.</para >
37
+ <para >
38
+ Analyzers can use this attribute to prevent warnings on calls to code that's
39
+ annotated as requiring that feature, when the callsite is guarded by a
40
+ call to the property.</para >
39
41
</remarks >
42
+ <example >
43
+ <format type =" text/markdown" ><![CDATA[
44
+ ```csharp
45
+ if (Feature.IsSupported)
46
+ Feature.Implementation();
47
+
48
+ public class Feature
49
+ {
50
+ [FeatureGuard(typeof(RequiresDynamicCodeAttribute))]
51
+ internal static bool IsSupported => RuntimeFeature.IsDynamicCodeSupported;
52
+
53
+ [RequiresDynamicCode("Feature requires dynamic code support.")]
54
+ internal static Implementation() => ...; // Uses dynamic code
55
+ }
56
+ ```
57
+
58
+ When the app is built with `<PublishAot>true</PublishAot>`, the call to
59
+ `Feature.Implementation()` doesn't produce analyzer warning
60
+ [IL3050](/dotnet/core/deploying/native-aot/warnings/il3050)
61
+ and `Feature.Implementation` code is removed when publishing.
62
+ ]]> </format >
63
+ </example >
40
64
</Docs >
41
65
<Members >
42
66
<Member MemberName =" .ctor" >
Original file line number Diff line number Diff line change 29
29
</Attributes >
30
30
<Docs >
31
31
<summary >
32
- <para >Indicates that the specified public static boolean get-only property</para >
33
- <para >corresponds to the feature switch specified by name.</para >
32
+ <para >
33
+ Indicates that the specified public static Boolean read-only property
34
+ corresponds to the feature switch specified by name.</para >
34
35
</summary >
35
36
<remarks >
36
- <para >IL rewriters and compilers can use this to substitute the return value</para >
37
- <para >of the specified property with the value of the feature switch.</para >
37
+ <para >
38
+ IL rewriters and compilers can use this attribute to substitute the return value
39
+ of the specified property with the value of the feature switch.</para >
38
40
</remarks >
41
+ <example >
42
+ <format type =" text/markdown" ><![CDATA[
43
+ ```csharp
44
+ if (Feature.IsSupported)
45
+ Feature.Implementation();
46
+
47
+ public class Feature
48
+ {
49
+ [FeatureSwitchDefinition("Feature.IsSupported")]
50
+ internal static bool IsSupported => AppContext.TryGetSwitch("Feature.IsSupported", out bool isEnabled) ? isEnabled : true;
51
+
52
+ internal static Implementation() => ...;
53
+ }
54
+ ```
55
+
56
+ When the app is trimmed with the following feature settings in the project file,
57
+ `Feature.IsSupported` is treated as `false`, and `Feature.Implementation` code is removed.
58
+
59
+ ```xml
60
+ <ItemGroup>
61
+ <RuntimeHostConfigurationOption Include="Feature.IsSupported" Value="false" />
62
+ </ItemGroup>
63
+ ```
64
+ ]]> </format >
65
+ </example >
39
66
</Docs >
40
67
<Members >
41
68
<Member MemberName =" .ctor" >
You can’t perform that action at this time.
0 commit comments