コード例 #1
0
        public void TestGenericsOverrideOfSpecificMethodWhereSubstitutionsAreNecessaryToComputeTheRightTargetToOverride()
        {
            var          algo          = new MetadataVirtualMethodAlgorithm();
            var          ilModule      = _context.GetModuleForSimpleName("ILTestAssembly");
            MetadataType myDerivedType = ilModule.GetType("MethodImplOverride1", "Derived");
            MetadataType baseType      = ilModule.GetType("MethodImplOverride1", "Base`2").MakeInstantiatedType(_context.GetWellKnownType(WellKnownType.Int32), _context.GetWellKnownType(WellKnownType.Int32));
            var          csModule      = _context.GetModuleForSimpleName("CoreTestAssembly");
            var          myGenericType = csModule.GetType("GenericTypes", "GenericClass`1");
            var          myGenericTypeInstantiatedOverBang0      = myGenericType.MakeInstantiatedType(_context.GetSignatureVariable(0, false));
            var          myGenericTypeInstantiatedOverBang0ByRef = myGenericTypeInstantiatedOverBang0.MakeByRefType();
            var          myGenericTypeInstantiatedOverBang1      = myGenericType.MakeInstantiatedType(_context.GetSignatureVariable(1, false));
            var          myGenericTypeInstantiatedOverBang1ByRef = myGenericTypeInstantiatedOverBang1.MakeByRefType();
            var          stringType = _context.GetWellKnownType(WellKnownType.String);

            MethodSignature sigBang0Bang1 = new MethodSignature(0, 0, stringType, new TypeDesc[] { myGenericTypeInstantiatedOverBang0ByRef, myGenericTypeInstantiatedOverBang1ByRef });
            MethodDesc      baseMethod0_1 = baseType.GetMethod("Method", sigBang0Bang1);

            MethodDesc virtualMethodBang0Bang1 = algo.FindVirtualFunctionTargetMethodOnObjectType(baseMethod0_1, myDerivedType);

            Assert.Equal(virtualMethodBang0Bang1.OwningType, myDerivedType);

            MethodSignature sigBang1Bang0 = new MethodSignature(0, 0, stringType, new TypeDesc[] { myGenericTypeInstantiatedOverBang1ByRef, myGenericTypeInstantiatedOverBang0ByRef });
            MethodDesc      baseMethod1_0 = baseType.GetMethod("Method", sigBang1Bang0);

            MethodDesc virtualMethodBang1Bang0 = algo.FindVirtualFunctionTargetMethodOnObjectType(baseMethod1_0, myDerivedType);

            Assert.Equal(virtualMethodBang1Bang0.OwningType, baseType);
        }
コード例 #2
0
        public void TestGenericsClassOverrideOfMethodWhereMethodHasBeenMovedFromTheTypeWhichPreviouslyDeclaredTheTypeToItsBaseType()
        {
            var algo             = new MetadataVirtualMethodAlgorithm();
            var csModule         = _context.GetModuleForSimpleName("CoreTestAssembly");
            var ilModule         = _context.GetModuleForSimpleName("ILTestAssembly");
            var doubleType       = _context.GetWellKnownType(WellKnownType.Double);
            var objectType       = _context.GetWellKnownType(WellKnownType.Object);
            var stringType       = _context.GetWellKnownType(WellKnownType.String);
            var intType          = _context.GetWellKnownType(WellKnownType.Int32);
            var myGenericType    = csModule.GetType("GenericTypes", "GenericClass`1");
            var genericTypeOfInt = myGenericType.MakeInstantiatedType(intType);
            var doubleArrayType  = doubleType.MakeArrayType();

            MetadataType myDerivedType = ilModule.GetType("MethodImplOverride1", "DerivedGenericsShape`1").MakeInstantiatedType(doubleType);
            MetadataType baseType      = ilModule.GetType("MethodImplOverride1", "BaseTestGenericsShape`4").MakeInstantiatedType(objectType, stringType, genericTypeOfInt, doubleArrayType);

            var bang0Type = _context.GetSignatureVariable(0, false);
            var bang1Type = _context.GetSignatureVariable(1, false);
            var bang2Type = _context.GetSignatureVariable(2, false);
            var bang3Type = _context.GetSignatureVariable(3, false);

            MethodSignature sigBang0Bang1 = new MethodSignature(0, 0, stringType, new TypeDesc[] { bang0Type, bang1Type });
            MethodDesc      baseMethod0_1 = baseType.GetMethod("Method", sigBang0Bang1);

            MethodDesc virtualMethodBang0Bang1 = algo.FindVirtualFunctionTargetMethodOnObjectType(baseMethod0_1, myDerivedType);

            Assert.Equal(virtualMethodBang0Bang1.OwningType, baseType);

            MethodSignature sigBang2Bang3 = new MethodSignature(0, 0, stringType, new TypeDesc[] { bang2Type, bang3Type });
            MethodDesc      baseMethod2_3 = null;

            // BaseMethod(!2,!3) has custom modifiers in its signature, and thus the sig is difficult to write up by hand. Just search for
            // it in an ad hoc manner
            foreach (MethodDesc method in baseType.GetMethods())
            {
                if (method.Name != "Method")
                {
                    continue;
                }

                if (method.GetTypicalMethodDefinition().Signature[0] == bang2Type)
                {
                    baseMethod2_3 = method;
                    break;
                }
            }

            MethodDesc virtualMethodBang1Bang0 = algo.FindVirtualFunctionTargetMethodOnObjectType(baseMethod2_3, myDerivedType);

            Assert.Equal(virtualMethodBang1Bang0.OwningType, myDerivedType);
        }
コード例 #3
0
        public void TestFindBaseUnificationGroup()
        {
            var          algo           = new MetadataVirtualMethodAlgorithm();
            var          ilModule       = _context.GetModuleForSimpleName("ILTestAssembly");
            MetadataType myDerived2Type = ilModule.GetType("VirtualFunctionOverride", "MyDerived2");

            Assert.NotNull(myDerived2Type);
            MethodDesc method = myDerived2Type.GetMethod("get_foo", null);

            Assert.NotNull(method);

            MethodDesc virtualMethod = algo.FindVirtualFunctionTargetMethodOnObjectType(method, myDerived2Type);

            Assert.NotNull(virtualMethod);
            Assert.Equal(method, virtualMethod);
        }
コード例 #4
0
        public void TestFindBaseUnificationGroup()
        {
            var algo = new MetadataVirtualMethodAlgorithm();
            var ilModule = _context.GetModuleForSimpleName("ILTestAssembly");
            MetadataType myDerived2Type = ilModule.GetType("VirtualFunctionOverride", "MyDerived2");
            Assert.NotNull(myDerived2Type);
            MethodDesc method = myDerived2Type.GetMethod("get_foo", null);
            Assert.NotNull(method);

            MethodDesc virtualMethod = algo.FindVirtualFunctionTargetMethodOnObjectType(method, myDerived2Type);
            Assert.NotNull(virtualMethod);
            Assert.Equal(method, virtualMethod);
        }