From 860e0a148ee0158219973d7d391f3186a39de662 Mon Sep 17 00:00:00 2001 From: jfrijters Date: Tue, 9 Feb 2010 07:57:49 +0000 Subject: [PATCH] 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. --- reflect/MemberInfo.cs | 13 +++++++++++++ reflect/Type.cs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/reflect/MemberInfo.cs b/reflect/MemberInfo.cs index 69c6bc4f..105c467a 100644 --- a/reflect/MemberInfo.cs +++ b/reflect/MemberInfo.cs @@ -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 GetCustomAttributesData() { return this.Module.GetCustomAttributes(this.MetadataToken); diff --git a/reflect/Type.cs b/reflect/Type.cs index 2612fa6c..83e38ad3 100644 --- a/reflect/Type.cs +++ b/reflect/Type.cs @@ -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)