I was suprised to see that the actual type of the object I get with x.GetType().GetProperty("Foo") is not System.Reflection.PropertyInfo but System.Reflection.RuntimePropertyInfo.
I don't see this type documentation in msdn or elsewhere.
My actual problem grows from reference-comparing two properties. I receive a property from third-party lib and compare it with a property which I get with .GetProperty("Foo") on the same type. I expected properties to be the same object (and they looks like the same property in "Locals" window while debugging), but they are not (GetHashCode result is different). So, I think it can somehow be related with the actual type of the property object which is System.Reflection.RuntimePropertyInfo.
What is System.Reflection.RuntimePropertyInfo? How to compare it? Does it behaves the same as usual PropertyInfo?
RuntimePropertyInfo is an internal implementation. It is a PropertyInfo, and in fact, GetProperty returns PropertyInfo (even if the underlying type is RuntimePropertyInfo).
The third-party lib is probably getting the property of a different type than you are?
new blah().GetType().GetProperty("Test") == new blah().GetType().GetProperty("Test")
Returns true.
PropertyInfo is an abstract class while RuntimePropertyInfo is the concrete implementation of PropertyInfo.
When we call Type.GetProperties() or Type.GetProperty() they actually returns the RuntimePropertyInfo.
The reason you are getting reference not equal could be because of the Type signature difference in the third-party lib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With