private void AssertHasSameMethod(Type type0, Type type1, string methodName, params Type[] parameterTypes)
        {
            var methodFromType0 = type0.GetMethod(methodName, parameterTypes);

            Assert.That(methodFromType0, Is.Not.Null);
            var methodFromType1 = type1.GetMethod(methodName, parameterTypes);

            Assert.That(methodFromType1, Is.Not.Null);
            Assert.That(_methodInfoEqualityComparerIgnoreVirtual.Equals(methodFromType0, methodFromType1), Is.True);
        }
        public void Equals_MethodFromBaseTypeHiddenByInterfaceMethod()
        {
            var methodFromBaseType = ScriptingHelper.GetInstanceMethod(typeof(Proxied), "PrependName", new[] { typeof(string) });
            var method             = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildChild), "PrependName", new[] { typeof(string) });

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));
            Assert.That(methodFromBaseType.GetBaseDefinition(), Is.Not.EqualTo(method.GetBaseDefinition()));

            // Default comparison taking all method attributes into account fails, since IPrependName adds the Final, Virtual and
            // VtableLayoutMask attributes.
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.False);

            // Comparing ignoring method attributes coming from IPrependName works.
            var comparerNoVirtualNoFinal = new MethodInfoEqualityComparer(~(MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.VtableLayoutMask));

            Assert.That(comparerNoVirtualNoFinal.Equals(methodFromBaseType, method), Is.True);
        }
        public void Ctor_Mask()
        {
            var method      = ScriptingHelper.GetInstanceMethod(typeof(CtorTest), "Foo", new[] { typeof(string) });
            var childMethod = ScriptingHelper.GetInstanceMethod(typeof(CtorTestChild), "Foo", new[] { typeof(string) });

            Assert.That(method.Attributes, Is.EqualTo(MethodAttributes.PrivateScope | MethodAttributes.Public | MethodAttributes.HideBySig));
            const MethodAttributes childMethodAdditionalAttributes = MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.VtableLayoutMask;

            Assert.That(childMethod.Attributes, Is.EqualTo(method.Attributes | childMethodAdditionalAttributes));

            var comparerDefault = new MethodInfoEqualityComparer();

            Assert.That(comparerDefault.Equals(method, childMethod), Is.False);

            var comparerNoVirtualNoFinal = new MethodInfoEqualityComparer(~childMethodAdditionalAttributes);

            Assert.That(comparerNoVirtualNoFinal.Equals(method, childMethod), Is.True);

            var comparerMethodFromBaseTypeAttributes = new MethodInfoEqualityComparer(method.Attributes);

            Assert.That(comparerMethodFromBaseTypeAttributes.Equals(method, childMethod), Is.True);
        }