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.#52509StephenMolloy merged 4 commits intodotnet:mainfrom
Conversation
mconnew
left a comment
There was a problem hiding this comment.
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.
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.
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.
| // 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.
would info.GetMethod?.IsPublic be more concise?
mconnew
left a comment
There was a problem hiding this comment.
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