-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance DynamicallyAccessedMembers Attribute to apply to class #49465
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @tommcdon, @krwq Issue DetailsBackground and MotivationThis proposal is taking @MichalStrehovsky's trimer proposal through its API change part. This proposal aligns well with the API proposal #49448 in enforcing the type that are required to be preserved for all derived types of a base class. #49448 helps with validating the type tree (parent type and its descendants) and this API enhancement will help with the enforcement. The Proposed APInamespace System.Diagnostics.CodeAnalysis
{
- [AttributeUsage(
- AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
- AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method,
- Inherited = false)]
- public sealed class DynamicallyAccessedMembersAttribute : Attribute
+ [AttributeUsage(
+ AttributeTargets.Interface | AttributeTargets.Class |
+ AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
+ AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method,
+ Inherited = false)]
+ public sealed class DynamicallyAccessedMembersAttribute : Attribute
} Usage ExamplesFor a concrete example, see the existing code in
If the EventSource Type is annotated with DynamicallyAccessedMembersAttribute as shown below, then the trimmer can preserve all methods of the derived EventSource and create a correct manifest for the derived EventSource type.
Without such support, some event methods might not be included in the manifest generation, which can cause tool problems among other issue. See this customer comment for more details. Alternative DesignsThe API proposal #49448 on its own RisksThis API might cause more code to be preserved than intended since it applies to all derived types of the annotated type.
|
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(
+ AttributeTargets.Class |
AttributeTargets.Field |
AttributeTargets.GenericParameter |
+ AttributeTargets.Interface |
+ AttributeTargets.Struct |
AttributeTargets.Method |
AttributeTargets.Parameter |
AttributeTargets.Property |
AttributeTargets.ReturnValue,
Inherited = false)]
public partial class DynamicallyAccessedMembersAttribute : Attribute
{
}
} |
Resolved by #49778. |
Background and Motivation
This proposal is taking @MichalStrehovsky's trimer proposal through its API change part. This proposal aligns well with the API proposal #49448 in enforcing the type that are required to be preserved for all derived types of a base class. #49448 helps with validating the type tree (parent type and its descendants) and this API enhancement will help with the enforcement.
The
DynamicallyAccessedMembersAttribute
attribute currently cannot be applied to a class or interface. Adding this support will allow developers to annotate a type to help the trimmer preserve its members that are being used. If the trimmer needs to keep the type, it will keep the required members on its derived types as well.Proposed API
Usage Examples
For a concrete example, see the existing code in
EventSources
which will create a manifest for a derivedEventSource
,If the EventSource Type is annotated with DynamicallyAccessedMembersAttribute as shown below, then the trimmer can preserve all methods of the derived EventSource and create a correct manifest for the derived EventSource type.
Without such support, some event methods might not be included in the manifest generation, which can cause tool problems among other issue. See this customer comment for more details.
Alternative Designs
The API proposal #49448 on its own
Risks
This API might cause more code to be preserved than intended since it applies to all derived types of the annotated type.
The text was updated successfully, but these errors were encountered: