Here's a simple test demonstrating the problem:
class MyBase { public int Foo { get; set; } } class MyClass : MyBase { } [TestMethod] public void TestPropertyCompare() { var prop1 = typeof(MyBase).GetProperty("Foo"); var prop2 = typeof(MyClass).GetProperty("Foo"); Assert.IsTrue(prop1 == prop2); // fails //Assert.IsTrue(prop1.Equals(prop2)); // also fails } I need a comparing method which will determine that these two properties are actually represent the same property. What is the correct way of doing this?
In particular I want to check if property actually comes from base class and not altered in any way like overriden (with override int Foo), hidden (with new int Foo) properties, interface properties (i.e. explicit implementation in derived class ISome.Foo) or any other way that lead to not calling MyBase.Foo when instanceOfDerived.Foo is used.
PropertyInfo.ReflectedTypeproperty value, and I want somehow ignore this