Open vyacheslav-volkov opened 5 months ago
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations See info in area-owners.md if you want to be subscribed.
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.
Why not just add a property to AttributeUsageAttribute
?
[AttributeUsage(AttributeTargets.Parameter, Trimmable = true)]
public class RequireStaticDelegateAttribute : Attribute
{
public bool IsError { get; set; }
}
JetBrains.Annotations
attributes are marked with [Conditional("JETBRAINS_ANNOTATIONS")]
. They will not be in your final build. You can also mark your own attributes as conditional.
Why not just add a property to AttributeUsageAttribute?
@hez2010 If this can be added to the base class it would be great.
JetBrains.Annotations attributes are marked with [Conditional("JETBRAINS_ANNOTATIONS")]. They will not be in your final build. You can also mark your own attributes as conditional.
@colejohnson66 If you want to ship your library to other developers, you will have to include them as internal classes or compile with JETBRAINS_ANNOTATIONS
flag set.
When building a library that is intended to be shipped to others, we can include the JetBrains Annotations source code directly in our project (or compile with the JETBRAINS_ANNOTATIONS flag set). https://blog.jetbrains.com/dotnet/2018/05/03/what-are-jetbrains-annotations/
Another example: many source generators use their own marker attributes just to generate sources, and these can be safely trimmed, the solution with ConditionalAttribute
does not solve all cases.
Many attributes are trimmable in some scenarios and not in other scenarios. The nullability attributes are a good example. They are trimmable unless the app uses NullabilityInfoContextSupport
. (#88805 tracks the problems around this.)
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
API Usage
Alternative Designs
No response
Risks
No response