-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Avoid Attribute.GetCustomAttributes() returning null for open generic type #65237
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
Changes from all commits
79c3416
f0f1e6c
fc0f401
224c985
a1717a9
3631f5a
e62566d
e0aef33
a3ecfe1
5179891
86160e1
0bfa71c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,12 +509,12 @@ public override object[] GetCustomAttributes(bool inherit) | |
|
||
public override object[] GetCustomAttributes(Type attributeType!!, bool inherit) | ||
{ | ||
if (MdToken.IsNullToken(m_tkParamDef)) | ||
return Array.Empty<object>(); | ||
|
||
if (attributeType.UnderlyingSystemType is not RuntimeType attributeRuntimeType) | ||
throw new ArgumentException(SR.Arg_MustBeType, nameof(attributeType)); | ||
|
||
if (MdToken.IsNullToken(m_tkParamDef)) | ||
return CustomAttribute.CreateAttributeArrayHelper(attributeRuntimeType, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was required to prevent a failure in Microsoft.CSharp.RuntimeBinder.Tests.AccessTests.PublicMethod(). I feel a bit weird exposing the CreateAttributeArrayHelper method as internal, but this is really the exact logic we want here. It makes this branch consistent with other GetCustomAttribute methods which all allow the consumer to cast the array to the requested attribute type. Moving this after the argument check presumably has some slight perf cost but ultimately feels more correct (and unless we change CreateAttributeArrayHelper to take There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Do we need a test to directly verify the behavior of ParamerInfo.GetCustomAttributes for this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
|
||
return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.