Ejemplo n.º 1
0
        public void TestFinalizeOverrideChecking()
        {
            MetadataType classWithFinalizer = _testModule.GetType("VirtualFunctionOverride", "ClassWithFinalizer");
            DefType      objectType         = _testModule.Context.GetWellKnownType(WellKnownType.Object);
            MethodDesc   finalizeMethod     = objectType.GetMethod("Finalize", new MethodSignature(MethodSignatureFlags.None, 0, _voidType, new TypeDesc[] { }));

            MethodDesc actualFinalizer = classWithFinalizer.FindVirtualFunctionTargetMethodOnObjectType(finalizeMethod);

            Assert.NotNull(actualFinalizer);
            Assert.NotEqual(actualFinalizer, finalizeMethod);
        }
Ejemplo n.º 2
0
        public void TestVirtualDispatchOnGenericType()
        {
            // Verifies that virtual dispatch to a non-generic method on a generic instantiation works
            DefType         objectType     = _context.GetWellKnownType(WellKnownType.Object);
            MethodSignature toStringSig    = new MethodSignature(MethodSignatureFlags.None, 0, _stringType, Array.Empty <TypeDesc>());
            MethodDesc      objectToString = objectType.GetMethod("ToString", toStringSig);

            Assert.NotNull(objectToString);
            MetadataType     openTestType     = _testModule.GetType("VirtualFunctionOverride", "SimpleGeneric`1");
            InstantiatedType testInstance     = openTestType.MakeInstantiatedType(new Instantiation(new TypeDesc[] { objectType }));
            MethodDesc       targetOnInstance = testInstance.GetMethod("ToString", toStringSig);

            MethodDesc targetMethod = testInstance.FindVirtualFunctionTargetMethodOnObjectType(objectToString);

            Assert.Equal(targetOnInstance, targetMethod);
        }