Added == and != operators to MemberInfo to mask the fact that we don't implement reference identity for various members (most notably the constructor wrappers, generic wrappers and events and properties).

Changed Type.Equals() to avoid infinite recursion, now that we overload the == operator.
This commit is contained in:
jfrijters 2010-02-09 07:57:49 +00:00
Родитель 855cc893ee
Коммит 860e0a148e
2 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -28,6 +28,9 @@ using System.Text;
namespace IKVM.Reflection
{
// disable warnings that complain about us having == and != operators without also overriding Equals/GetHashCode,
// this is intentional because most subtypes use reference equality
#pragma warning disable 660, 661
public abstract class MemberInfo
{
public abstract string Name { get; }
@ -49,6 +52,16 @@ namespace IKVM.Reflection
return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
}
public static bool operator ==(MemberInfo m1, MemberInfo m2)
{
return ReferenceEquals(m1, m2) || (!ReferenceEquals(m1, null) && m1.Equals(m2));
}
public static bool operator !=(MemberInfo m1, MemberInfo m2)
{
return !(m1 == m2);
}
internal virtual IList<CustomAttributeData> GetCustomAttributesData()
{
return this.Module.GetCustomAttributes(this.MetadataToken);

Просмотреть файл

@ -211,7 +211,7 @@ namespace IKVM.Reflection
public bool Equals(Type type)
{
return type != null && type.UnderlyingSystemType == this.UnderlyingSystemType;
return !ReferenceEquals(type, null) && ReferenceEquals(type.UnderlyingSystemType, this.UnderlyingSystemType);
}
public override bool Equals(object obj)