Skip to content

Conversation

@baronfel
Copy link
Member

@baronfel baronfel commented Jan 4, 2021

Closes #9256 by checking all super types of an attribute for AllowMultiple.

This is done by creating a sequence of types that need to be checked for AllowMultiple, and walking that sequence until one of them returns a concrete value for AllowMultiple. This is a pretty simplistic strategy, and I'm not sure how it interacts with the Inherited property of AttributeUsage. I've added a test case as well to prove that this works as expected, though I could certainly use some additional test cases to ensure this works across all cases. If there is more logic necessary to take Inherited into consideration, it should be pretty easy to stop the type-hierarchy traversal just by returning a Some value at that level, which would satisfy the tryPick.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it. Looks like a lame macos failure again

@cartermp cartermp closed this Jan 4, 2021
@cartermp cartermp reopened this Jan 4, 2021
@baronfel
Copy link
Member Author

baronfel commented Jan 4, 2021

I would like someone smarter than me to think through the Inherited case I sketched out and decide what exactly we should do. The API Docs for AttributeUsageAttribute.Inherited leave me a bit confused about what the exact logic should be.

@NinoFloris
Copy link
Contributor

I might be wrong about this but I believe Inherited is entirely a runtime concern, reflection (and maybe the clr type system) takes it into account when queried.

@KevinRansom
Copy link
Contributor

Thanks for this looks Good,

Kevin

@cartermp cartermp merged commit 142c034 into dotnet:main Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeUsage AllowMultiple and AttributeTargets is not inherited

4 participants