Skip to content

[API Proposal]: Add the ability to trim custom attributes #102802

Open
@vyacheslav-volkov

Description

@vyacheslav-volkov

Background and motivation

I'm using JetBrains.Annotations as internal classes in my library and since trimmer doesn't know about these attributes they will be preserved in the final build, but since these attributes are only for code annotations I think it would be nice to have some sort of mechanism, allowing you to mark them as safe for trimming.
I suggest adding a TrimmableAttributeAttribute which we can use to mark custom code annotation attributes and the linker will know that this attribute can be safely trimmed.

API Proposal

namespace System.Diagnostics.CodeAnalysis;

[AttributeUsage(AttributeTargets.Class)]
public sealed class TrimmableAttributeAttribute : Attribute;

API Usage

[AttributeUsage(AttributeTargets.Parameter)]
[TrimmableAttribute]
public class RequireStaticDelegateAttribute : Attribute
{
    public bool IsError { get; set; }
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-Tools-ILLink.NET linker development as well as trimming analyzerslinkable-frameworkIssues associated with delivering a linker friendly framework

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions