Ejemplo n.º 1
0
        public void MethodHandleTest()
        {
            var comparer = ComparerBuilder <MethodInfo> .GetEqualityComparer(m => m.MethodHandle);

            var a  = typeof(A).GetMethod("M");
            var b  = typeof(B).GetMethod("M");
            var b2 = b.GetBaseDefinition();

            Assert.False(a.Equals(b), "MethodInfo fails");
            Assert.True(a.Equals(b2), "MethodInfo fails");

            Assert.False(a.MethodHandle.Equals(b.MethodHandle), "MethodHandle fails");
            Assert.True(a.MethodHandle.Equals(b2.MethodHandle), "MethodHandle fails");

            Assert.False(EqualityComparer <RuntimeMethodHandle> .Default.Equals(a.MethodHandle, b.MethodHandle), "EqualityComparer fails");
            Assert.True(EqualityComparer <RuntimeMethodHandle> .Default.Equals(a.MethodHandle, b2.MethodHandle), "EqualityComparer fails");

            Assert.False(comparer.Equals(a, b), "ComparerBuilder fails");
            Assert.True(comparer.Equals(a, b2), "ComparerBuilder fails");
        }