vendredi 22 avril 2016

How to compare same PropertyInfo with different ReflectedType values?

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 equal. What is the correct way of doing this?

I see that there are few problems: overriden/hidden properties, interface properties. Is it so hard to compare properties?





Aucun commentaire:

Enregistrer un commentaire