Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit e7fa619

Browse files
Turn on the AOT analyzer. (#92)
* Turn on the AOT analyzer. * Address feedback * Add missing types. * Fix build and react to conflicts. * Fix failing test. * Address feedback.
1 parent c0e1d0d commit e7fa619

22 files changed

+522
-68
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis;
5+
6+
/// <summary>
7+
/// Specifies the types of members that are dynamically accessed.
8+
///
9+
/// This enumeration has a <see cref="FlagsAttribute"/> attribute that allows a
10+
/// bitwise combination of its member values.
11+
/// </summary>
12+
[Flags]
13+
internal enum DynamicallyAccessedMemberTypes
14+
{
15+
/// <summary>
16+
/// Specifies no members.
17+
/// </summary>
18+
None = 0,
19+
20+
/// <summary>
21+
/// Specifies the default, parameterless public constructor.
22+
/// </summary>
23+
PublicParameterlessConstructor = 0x0001,
24+
25+
/// <summary>
26+
/// Specifies all public constructors.
27+
/// </summary>
28+
PublicConstructors = 0x0002 | PublicParameterlessConstructor,
29+
30+
/// <summary>
31+
/// Specifies all non-public constructors.
32+
/// </summary>
33+
NonPublicConstructors = 0x0004,
34+
35+
/// <summary>
36+
/// Specifies all public methods.
37+
/// </summary>
38+
PublicMethods = 0x0008,
39+
40+
/// <summary>
41+
/// Specifies all non-public methods.
42+
/// </summary>
43+
NonPublicMethods = 0x0010,
44+
45+
/// <summary>
46+
/// Specifies all public fields.
47+
/// </summary>
48+
PublicFields = 0x0020,
49+
50+
/// <summary>
51+
/// Specifies all non-public fields.
52+
/// </summary>
53+
NonPublicFields = 0x0040,
54+
55+
/// <summary>
56+
/// Specifies all public nested types.
57+
/// </summary>
58+
PublicNestedTypes = 0x0080,
59+
60+
/// <summary>
61+
/// Specifies all non-public nested types.
62+
/// </summary>
63+
NonPublicNestedTypes = 0x0100,
64+
65+
/// <summary>
66+
/// Specifies all public properties.
67+
/// </summary>
68+
PublicProperties = 0x0200,
69+
70+
/// <summary>
71+
/// Specifies all non-public properties.
72+
/// </summary>
73+
NonPublicProperties = 0x0400,
74+
75+
/// <summary>
76+
/// Specifies all public events.
77+
/// </summary>
78+
PublicEvents = 0x0800,
79+
80+
/// <summary>
81+
/// Specifies all non-public events.
82+
/// </summary>
83+
NonPublicEvents = 0x1000,
84+
85+
/// <summary>
86+
/// Specifies all interfaces implemented by the type.
87+
/// </summary>
88+
Interfaces = 0x2000,
89+
90+
/// <summary>
91+
/// Specifies all non-public constructors, including those inherited from base classes.
92+
/// </summary>
93+
NonPublicConstructorsWithInherited = NonPublicConstructors | 0x4000,
94+
95+
/// <summary>
96+
/// Specifies all non-public methods, including those inherited from base classes.
97+
/// </summary>
98+
NonPublicMethodsWithInherited = NonPublicMethods | 0x8000,
99+
100+
/// <summary>
101+
/// Specifies all non-public fields, including those inherited from base classes.
102+
/// </summary>
103+
NonPublicFieldsWithInherited = NonPublicFields | 0x10000,
104+
105+
/// <summary>
106+
/// Specifies all non-public nested types, including those inherited from base classes.
107+
/// </summary>
108+
NonPublicNestedTypesWithInherited = NonPublicNestedTypes | 0x20000,
109+
110+
/// <summary>
111+
/// Specifies all non-public properties, including those inherited from base classes.
112+
/// </summary>
113+
NonPublicPropertiesWithInherited = NonPublicProperties | 0x40000,
114+
115+
/// <summary>
116+
/// Specifies all non-public events, including those inherited from base classes.
117+
/// </summary>
118+
NonPublicEventsWithInherited = NonPublicEvents | 0x80000,
119+
120+
/// <summary>
121+
/// Specifies all public constructors, including those inherited from base classes.
122+
/// </summary>
123+
PublicConstructorsWithInherited = PublicConstructors | 0x100000,
124+
125+
/// <summary>
126+
/// Specifies all public nested types, including those inherited from base classes.
127+
/// </summary>
128+
PublicNestedTypesWithInherited = PublicNestedTypes | 0x200000,
129+
130+
/// <summary>
131+
/// Specifies all constructors, including those inherited from base classes.
132+
/// </summary>
133+
AllConstructors = PublicConstructorsWithInherited | NonPublicConstructorsWithInherited,
134+
135+
/// <summary>
136+
/// Specifies all methods, including those inherited from base classes.
137+
/// </summary>
138+
AllMethods = PublicMethods | NonPublicMethodsWithInherited,
139+
140+
/// <summary>
141+
/// Specifies all fields, including those inherited from base classes.
142+
/// </summary>
143+
AllFields = PublicFields | NonPublicFieldsWithInherited,
144+
145+
/// <summary>
146+
/// Specifies all nested types, including those inherited from base classes.
147+
/// </summary>
148+
AllNestedTypes = PublicNestedTypesWithInherited | NonPublicNestedTypesWithInherited,
149+
150+
/// <summary>
151+
/// Specifies all properties, including those inherited from base classes.
152+
/// </summary>
153+
AllProperties = PublicProperties | NonPublicPropertiesWithInherited,
154+
155+
/// <summary>
156+
/// Specifies all events, including those inherited from base classes.
157+
/// </summary>
158+
AllEvents = PublicEvents | NonPublicEventsWithInherited,
159+
160+
/// <summary>
161+
/// Specifies all members.
162+
/// </summary>
163+
All = ~None
164+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis;
5+
6+
/// <summary>
7+
/// Indicates that certain members on a specified <see cref="Type"/> are accessed dynamically,
8+
/// for example through <see cref="Reflection"/>.
9+
/// </summary>
10+
/// <remarks>
11+
/// This allows tools to understand which members are being accessed during the execution
12+
/// of a program.
13+
///
14+
/// This attribute is valid on members whose type is <see cref="Type"/> or <see cref="string"/>.
15+
///
16+
/// When this attribute is applied to a location of type <see cref="string"/>, the assumption is
17+
/// that the string represents a fully qualified type name.
18+
///
19+
/// When this attribute is applied to a class, interface, or struct, the members specified
20+
/// can be accessed dynamically on <see cref="Type"/> instances returned from calling
21+
/// <see cref="object.GetType"/> on instances of that class, interface, or struct.
22+
///
23+
/// If the attribute is applied to a method it's treated as a special case and it implies
24+
/// the attribute should be applied to the "this" parameter of the method. As such the attribute
25+
/// should only be used on instance methods of types assignable to System.Type (or string, but no methods
26+
/// will use it there).
27+
/// </remarks>
28+
[AttributeUsage(
29+
AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
30+
AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method |
31+
AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct,
32+
Inherited = false)]
33+
internal sealed class DynamicallyAccessedMembersAttribute : Attribute
34+
{
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="DynamicallyAccessedMembersAttribute"/> class
37+
/// with the specified member types.
38+
/// </summary>
39+
/// <param name="memberTypes">The types of members dynamically accessed.</param>
40+
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
41+
{
42+
MemberTypes = memberTypes;
43+
}
44+
45+
/// <summary>
46+
/// Gets the <see cref="DynamicallyAccessedMemberTypes"/> which specifies the type
47+
/// of members dynamically accessed.
48+
/// </summary>
49+
public DynamicallyAccessedMemberTypes MemberTypes { get; }
50+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis;
5+
6+
/// <summary>
7+
/// Indicates that the specified method requires the ability to generate new code at runtime,
8+
/// for example through <see cref="Reflection"/>.
9+
/// </summary>
10+
/// <remarks>
11+
/// This allows tools to understand which methods are unsafe to call when compiling ahead of time.
12+
/// </remarks>
13+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)]
14+
internal sealed class RequiresDynamicCodeAttribute : Attribute
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="RequiresDynamicCodeAttribute"/> class
18+
/// with the specified message.
19+
/// </summary>
20+
/// <param name="message">
21+
/// A message that contains information about the usage of dynamic code.
22+
/// </param>
23+
public RequiresDynamicCodeAttribute(string message)
24+
{
25+
Message = message;
26+
}
27+
28+
/// <summary>
29+
/// Gets a message that contains information about the usage of dynamic code.
30+
/// </summary>
31+
public string Message { get; }
32+
33+
/// <summary>
34+
/// Gets or sets an optional URL that contains more information about the method,
35+
/// why it requires dynamic code, and what options a consumer has to deal with it.
36+
/// </summary>
37+
public string? Url { get; set; }
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis;
5+
6+
/// <summary>
7+
/// Indicates that the specified method requires dynamic access to code that is not referenced
8+
/// statically, for example through <see cref="System.Reflection"/>.
9+
/// </summary>
10+
/// <remarks>
11+
/// This allows tools to understand which methods are unsafe to call when removing unreferenced
12+
/// code from an application.
13+
/// </remarks>
14+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)]
15+
internal sealed class RequiresUnreferencedCodeAttribute : Attribute
16+
{
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="RequiresUnreferencedCodeAttribute"/> class
19+
/// with the specified message.
20+
/// </summary>
21+
/// <param name="message">
22+
/// A message that contains information about the usage of unreferenced code.
23+
/// </param>
24+
public RequiresUnreferencedCodeAttribute(string message)
25+
{
26+
Message = message;
27+
}
28+
29+
/// <summary>
30+
/// Gets a message that contains information about the usage of unreferenced code.
31+
/// </summary>
32+
public string Message { get; }
33+
34+
/// <summary>
35+
/// Gets or sets an optional URL that contains more information about the method,
36+
/// why it requires unreferenced code, and what options a consumer has to deal with it.
37+
/// </summary>
38+
public string? Url { get; set; }
39+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis;
5+
6+
/// <summary>
7+
/// /// Suppresses reporting of a specific rule violation, allowing multiple suppressions on a
8+
/// single code artifact.
9+
/// </summary>
10+
/// <remarks>
11+
/// <see cref="UnconditionalSuppressMessageAttribute"/> is different than
12+
/// <see cref="SuppressMessageAttribute"/> in that it doesn't have a
13+
/// <see cref="ConditionalAttribute"/>. So it is always preserved in the compiled assembly.
14+
/// </remarks>
15+
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
16+
internal sealed class UnconditionalSuppressMessageAttribute : Attribute
17+
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="UnconditionalSuppressMessageAttribute"/>
20+
/// class, specifying the category of the tool and the identifier for an analysis rule.
21+
/// </summary>
22+
/// <param name="category">The category for the attribute.</param>
23+
/// <param name="checkId">The identifier of the analysis rule the attribute applies to.</param>
24+
public UnconditionalSuppressMessageAttribute(string category, string checkId)
25+
{
26+
Category = category;
27+
CheckId = checkId;
28+
}
29+
30+
/// <summary>
31+
/// Gets the category identifying the classification of the attribute.
32+
/// </summary>
33+
/// <remarks>
34+
/// The <see cref="Category"/> property describes the tool or tool analysis category
35+
/// for which a message suppression attribute applies.
36+
/// </remarks>
37+
public string Category { get; }
38+
39+
/// <summary>
40+
/// Gets the identifier of the analysis tool rule to be suppressed.
41+
/// </summary>
42+
/// <remarks>
43+
/// Concatenated together, the <see cref="Category"/> and <see cref="CheckId"/>
44+
/// properties form a unique check identifier.
45+
/// </remarks>
46+
public string CheckId { get; }
47+
48+
/// <summary>
49+
/// Gets or sets the scope of the code that is relevant for the attribute.
50+
/// </summary>
51+
/// <remarks>
52+
/// The Scope property is an optional argument that specifies the metadata scope for which
53+
/// the attribute is relevant.
54+
/// </remarks>
55+
public string? Scope { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets a fully qualified path that represents the target of the attribute.
59+
/// </summary>
60+
/// <remarks>
61+
/// The <see cref="Target"/> property is an optional argument identifying the analysis target
62+
/// of the attribute. An example value is "System.IO.Stream.ctor():System.Void".
63+
/// Because it is fully qualified, it can be long, particularly for targets such as parameters.
64+
/// The analysis tool user interface should be capable of automatically formatting the parameter.
65+
/// </remarks>
66+
public string? Target { get; set; }
67+
68+
/// <summary>
69+
/// Gets or sets an optional argument expanding on exclusion criteria.
70+
/// </summary>
71+
/// <remarks>
72+
/// The <see cref="MessageId"/> property is an optional argument that specifies additional
73+
/// exclusion where the literal metadata target is not sufficiently precise. For example,
74+
/// the <see cref="UnconditionalSuppressMessageAttribute"/> cannot be applied within a method,
75+
/// and it may be desirable to suppress a violation against a statement in the method that will
76+
/// give a rule violation, but not against all statements in the method.
77+
/// </remarks>
78+
public string? MessageId { get; set; }
79+
80+
/// <summary>
81+
/// Gets or sets the justification for suppressing the code analysis message.
82+
/// </summary>
83+
public string? Justification { get; set; }
84+
}

0 commit comments

Comments
 (0)