I have two classes that are decorated with the same attribute but different values. When I dump them in LINQPad I can see that they are different but when I do x.Equals(y)
then it yields true
even though the implementation of Equals
actually compares property values.
This code reproduces this issue:
void Main()
{
var a1 = typeof(T1).GetCustomAttribute<A2>().Dump();
var a2 = typeof(T3).GetCustomAttribute<A2>().Dump();
a1.Equals(a2).Dump();
}
[A1(V = "I1")]
interface I1
{
[A1(V = "I1.P1")]
string P1 { get; set; }
}
[A2(V = "T1")] // <-- typeof(T1).GetCustomAttribute<A2>()
class T1 : I1
{
[A1(V = "T1.P1")]
public virtual string P1 { get; set; }
}
class T2 : T1 { }
[A1(V = "T3"), A2(V = "T3")] // <-- typeof(T3).GetCustomAttribute<A2>()
class T3 : T2
{
[A1(V = "T3.P1")]
public override string P1 { get; set; }
}
class A1 : Attribute { public string V { get; set; } }
class A2 : A1 { }
And these are the results:
UserQuery+A2 TypeId = typeof(A2) V = T1 UserQuery+A2 TypeId = typeof(A2) V = T3 True // <-- a1.Equals(a2).Dump();
What am I missing here and how can I properly compare them?