-
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
Keep looking up derived chain for Property.Get if it doesn't exist. #52509
Keep looking up derived chain for Property.Get if it doesn't exist. #52509
Conversation
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 this a regression from NetFx or a long time bug that's now been resolved for .NET 6?
21cabff
to
d15494e
Compare
// getter at this level of inheritance. If that's the case, we need to look | ||
// up the chain to find the right PropertyInfo for the getter. | ||
if (memberInfo is PropertyInfo propInfo && propInfo.GetMethod == 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.
What happens if a base type has a property called Foo and the derived type has a method called Foo? GetMember would return the MethodInfo for the dervived Foo method and this code won't search the base type for the property.
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.
Crikey! But as we've talked about before, 'hidden' members are a mess in the serializers right now. This would fall under the broader work we need to do in #53051.
// The property name is a match. It might be an override, or | ||
// it might be hiding. Either way, check to see if the derived | ||
// property has a getter that is useable for serialization. | ||
if (info.GetMethod != null && !info.GetMethod!.IsPublic | ||
&& memberInfoToBeReplaced is PropertyInfo |
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.
would info.GetMethod?.IsPublic
be more concise?
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.
I don't think the question of a method hiding the property is one to be too concerned with as I believe it's an existing problem which we haven't had any complaints about.
Keep looking up derived chain for Property.Get.
When dealing with a derived type, we have code that looks up
the derived chain looking for property getters if it doesn't
exist directly on the class being serialized. This code was tripping
up when a class in the chain declared a setter for the property
without a getter though. In this case, we should keep going
up the chain looking for a getter instead of failing.
Fixes #36181 and #38025