File tree Expand file tree Collapse file tree 2 files changed +53
-9
lines changed
xml/System.Diagnostics.CodeAnalysis Expand file tree Collapse file tree 2 files changed +53
-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 get-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 to prevent warnings on calls to code that is
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
+ <code language =" csharp" >
44
+ if (Feature.IsSupported)
45
+ Feature.Implementation();
46
+
47
+ public class Feature
48
+ {
49
+ [FeatureGuard(typeof(RequiresDynamicCodeAttribute))]
50
+ internal static bool IsSupported => RuntimeFeature.IsDynamicCodeSupported;
51
+
52
+ [RequiresDynamicCode("Feature requires dynamic code support.")]
53
+ internal static Implementation() => ...; // Uses dynamic code
54
+ }
55
+ </code >
56
+ When the app is built with `& ltPublishAot> true& lt/PublishAot> `, the call to
57
+ `Feature.Implementation()` doesn't produce analyzer warning
58
+ <see href =" https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/warnings/il3050" >IL3050</see >,
59
+ and `Feature.Implementation` code is removed when publishing.
60
+ </example >
40
61
</Docs >
41
62
<Members >
42
63
<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 get-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 to substitute the return value
39
+ of the specified property with the value of the feature switch.</para >
38
40
</remarks >
41
+ <example >
42
+ <code language =" csharp" >
43
+ if (Feature.IsSupported)
44
+ Feature.Implementation();
45
+
46
+ public class Feature
47
+ {
48
+ [FeatureSwitchDefinition("Feature.IsSupported")]
49
+ internal static bool IsSupported => AppContext.TryGetSwitch("Feature.IsSupported", out bool isEnabled) ? isEnabled : true;
50
+
51
+ internal static Implementation() => ...;
52
+ }
53
+ </code >
54
+ When the app is trimmed with the following feature settings in the project file,
55
+ `Feature.IsSupported` is treated as `false`, and `Feature.Implementation` code is removed.
56
+ <code language =" xml" >
57
+ < ItemGroup>
58
+ < RuntimeHostConfigurationOption Include="Feature.IsSupported" Value="false" />
59
+ < /ItemGroup>
60
+ </code >
61
+ </example >
39
62
</Docs >
40
63
<Members >
41
64
<Member MemberName =" .ctor" >
You can’t perform that action at this time.
0 commit comments