-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Get info about generic attributes #64169
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsBackground and motivationMake it easier to handle generic attributes. API Proposal
API Usagevar Attrs = Attribute.GetCustomAttributes(this.GetType(), typeof(TestAttribute<>));
var type = Attrs[0].TypeArgs[0]; Alternative DesignsNo response RisksNo response
|
I'm not certain why this is needed. Why not just do |
For adding a new property i agree with @CyrusNajmabadi, doesn't seem we need to add property for
Makes sense to me, will discuss with the team. As this is not a new API suggestion and we don't need the other API suggestion removing the |
Just to clarify, is the proposal that calling any
Then @buyaa-n I'm potentially interested in working on this but I'd want to be sure of the expected behavior first. |
That is my understanding of the ask. I think it makes sense, although I don't know where this "open generic" convention is used elsewhere for similar filtering or scoping. Since the workaround is not that difficult (get all custom attributes and manually filter) this feature is lower-priority. |
@GrabYourPitchforks if we add a new convention for open generic types to be used to mean all closed, does this rise to the level of discussing it in an API review meeting? |
I believe that should depend on if the |
@GrabYourPitchforks suggested to go through API review |
Yes, reflection should support retrieving attribute by open generic types. And yes, using a base type should also work, assuming |
Thanks @madelson, the expected behavior is approved, do you still interested in working on this? |
@buyaa-n sure I'll try to take a look at it this weekend to get a sense of what is involved. |
@buyaa-n :
I'm a bit confused. Are we talking about the For example:
What am I missing? |
You are right, I have mistaken about the parameter. In this case the behavior should be same as how it works for non generic attributes, and |
Filtering on an open generic type retrieves all attributes that are or are derived from constructed instances of that type. fix dotnet#64169
Background and motivation
Make it easier to handle generic attributes.
API Proposal
Attribute.GetCustomAttributes
Method.. It currently returns an empty array.Add an the instance propertyTypeArgs
to the Attribute class that returns all type args if any.API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: