-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[New API] Expose a way to identify custom attributes #53410
Comments
@AlekseyTs as API owner. |
I think a better API would be IsReturnType and emittingAssemblyAttributesInNetModule should not be needed to determine whether an attribute is real custom attribute or pseudo-custom attribute. For EnC purposes we can ignore netmodules. Those are legacy consturcts and already not supported by EnC. |
I think I disagree with that. Whether the attribute is going to be translated into an alternative representation in metadata depends on the application target as well. |
We have attributes that are emitted to CustomAttribute table when applied on one target and to metadata flags when on a different target? The ECMA spec defines pseudo-custom attributes like so:
...
|
I agree, and this is what I meant in one of my sentences under "Alternative Designs" but you worded it better than me :) In fact, I would imagine that for EnC it would just always pass false for |
I believe the ECMA spec is only concerned by scenarios where runtime behavior is affected by the attributes and where metadata provide an alternative way to capture the information (through special flags, etc.), which is target specific. When the same attribute is applied to a target that doesn't have that special metadata encoding defined, we have no other choice but emit the attribute as is, which I believe we do. |
It feels like AttributeData can simply have a property "IsEmitted", which can cover conditional attributes and pseudo attributes. Or we can have two separate properties. |
@AlekseyTs I've applied api-needs-work for now. When you're satisfied with the current proposal, please remove it and apply |
@davidwengier It doesn't look like you made any adjustments to the proposal based on the discussion. You "voted" for #53410 (comment). would you like to adjust the proposal based on that? |
@AlekseyTs Apologies, I was unclear on the process. Thank you for the reminder, I've updated the issue description. |
API ReviewAPI Approved. |
Background and Motivation
Hot Reload is one of the big features of .NET 6 and a key scenario for it is the ability to create new route end points in ASP.NET Core web applications and APIs. These end points are denoted by methods that are annotated with an attribute (eg
HttpGet
) however currently Edit and Continue, which is the system that powers Hot Reload, doesn't support modifying attributes.#52986 solves the broad issue and allows Edit and Continue to modify attributes, but we don't have a way to enforce that only attributes emitted in the
CustomAttributes
metadata table are able to be modified at run time. The compiler currently has this information, for some attributes, in theAttributeData.ShouldEmitAttribute
method:https://github.com/dotnet/roslyn/blob/main/src/Compilers/CSharp/Portable/Symbols/Attributes/AttributeData.cs#L687
This proposal is to add a public API for exposing the information in that method.
Proposed API
namespace Microsoft.CodeAnalysis { public abstract class AttributeData { + public bool IsEmitted { get; } }
Usage Examples
Alternative Designs
I went with the approach of just exposing a method that already exists, but the "Should Emit" part of the name is a little odd for a public API. I considered
IsCustomAttribute
, but wasn't sure if the custom attribute part of the name would be confusing in this context, and thought the return type parameter made it odd too, because surely an attribute is either custom or not, irrelevant of whether used on a return type?The other option of course is to have this new API be much more simple, and remove the parameters altogether, and just have a list of attributes that are known to not be emitted in any circumstance.
Risks
By exposing an existing method the risks are minimal. Using a different name, or getting rid of the parameters, introduces a risk in terms of having multiple things to maintain.
The text was updated successfully, but these errors were encountered: