-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Reflection.CustomAttributeFormatException thrown on a retrieval of derived attribute with overridden property getter #110945
base: main
Are you sure you want to change the base?
Conversation
…l of derived attribute with overridden property getter
@@ -1580,7 +1580,7 @@ private static void AddCustomAttributes( | |||
RuntimeMethodInfo setMethod = property.GetSetMethod(true)!; | |||
|
|||
// Public properties may have non-public setter methods | |||
if (!setMethod.IsPublic) | |||
if (setMethod == null || !setMethod.IsPublic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is null
to avoid unnecessary comparison operator
@@ -1580,7 +1580,7 @@ private static void AddCustomAttributes( | |||
RuntimeMethodInfo setMethod = property.GetSetMethod(true)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nullability suppression should also be removed
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderSetCustomAttribute.cs
Outdated
Show resolved
Hide resolved
Type? baseDeclaredType = declaredType.BaseType; | ||
|
||
while ((m_getterMethod == null || m_setterMethod == null) | ||
&& baseDeclaredType != null && baseDeclaredType is RuntimeType baseDeclaredRuntimeType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& baseDeclaredType != null && baseDeclaredType is RuntimeType baseDeclaredRuntimeType) | |
&& baseDeclaredType is RuntimeType baseDeclaredRuntimeType) |
The pattern match also does a null check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some test failures for Mono; the changes need to be ported to Mono as well.
out _, out _, out _, | ||
out m_getterMethod, out m_setterMethod, out m_otherMethod, | ||
out isPrivate, out m_bindingFlags); | ||
|
||
// lookup getter/setter when getter and setter are inherited from base class but just a setter/getter is overridden on a sub type | ||
if ((m_getterMethod != null && m_getterMethod.IsVirtual && m_setterMethod == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: as mentioned earlier, is null
and is not null
is preferred over == null
and != null
since it will prevent a call to the ==
or !=
operator if that is overridden. In this case, it is just more obvious to understand intent when using RuntimeMethodInfo
doesn't overload those operators so it doesn't matter butis
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuntimeMethodInfo doesn't overload those operators so it doesn't matter
MethodInfo does overload those operators. MethodInfo operators are going to be selected to compare RuntimeMethodInfo quick test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops thanks; updated comment
out _, out _, out _, | ||
out m_getterMethod, out m_setterMethod, out m_otherMethod, | ||
out isPrivate, out m_bindingFlags); | ||
|
||
// lookup getter/setter when getter and setter are inherited from base class but just a setter/getter is overridden on a sub type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: start a comment with upper case letter and end with a period.
Fixes #110412