public void TestMethodLookup() { MetadataType t = _testModule.GetType("GenericTypes", "GenericClass`1").MakeInstantiatedType(_context.GetWellKnownType(WellKnownType.Int32)); MethodSignature sig = new MethodSignature(MethodSignatureFlags.None, 0, _context.GetSignatureVariable(0, false), new TypeDesc[0] { }); MethodDesc fooMethod = t.GetMethod("Foo", sig); Assert.NotNull(fooMethod); }
public void TestVirtualDispatchOnGenericTypeWithOverload() { MetadataType openDerived = _testModule.GetType("VirtualFunctionOverride", "DerivedGenericWithOverload`1"); MetadataType derivedInstance = openDerived.MakeInstantiatedType(_stringType); MetadataType baseInstance = (MetadataType)derivedInstance.BaseType; MethodDesc baseNongenericOverload = baseInstance.GetMethod("MyMethod", new MethodSignature(MethodSignatureFlags.None, 0, _voidType, new TypeDesc[] { _stringType })); MethodDesc derivedNongenericOverload = derivedInstance.GetMethod("MyMethod", new MethodSignature(MethodSignatureFlags.None, 0, _voidType, new TypeDesc[] { _stringType })); MethodDesc nongenericTargetOverload = derivedInstance.FindVirtualFunctionTargetMethodOnObjectType(baseNongenericOverload); Assert.Equal(derivedNongenericOverload, nongenericTargetOverload); MethodDesc baseGenericOverload = baseInstance.GetMethod("MyMethod", new MethodSignature(MethodSignatureFlags.None, 0, _voidType, new TypeDesc[] { _context.GetSignatureVariable(0, false) })); MethodDesc derivedGenericOverload = derivedInstance.GetMethod("MyMethod", new MethodSignature(MethodSignatureFlags.None, 0, _voidType, new TypeDesc[] { _context.GetSignatureVariable(0, false) })); MethodDesc genericTargetOverload = derivedInstance.FindVirtualFunctionTargetMethodOnObjectType(baseGenericOverload); Assert.Equal(derivedGenericOverload, genericTargetOverload); }
public void TestGenericTypes(CanonicalizationMode algorithmType) { _context.CanonMode = algorithmType; // Canonical forms of reference type over two different reference types are equivalent var referenceOverReference = _genericReferenceType.MakeInstantiatedType(_referenceType); var referenceOverOtherReference = _genericReferenceType.MakeInstantiatedType(_otherReferenceType); Assert.Same( referenceOverReference.ConvertToCanonForm(CanonicalFormKind.Specific), referenceOverOtherReference.ConvertToCanonForm(CanonicalFormKind.Specific)); Assert.Same( referenceOverReference.ConvertToCanonForm(CanonicalFormKind.Universal), referenceOverOtherReference.ConvertToCanonForm(CanonicalFormKind.Universal)); var referenceOverReferenceOverReference = _genericReferenceType.MakeInstantiatedType(referenceOverReference); Assert.Same( referenceOverReference.ConvertToCanonForm(CanonicalFormKind.Specific), referenceOverReferenceOverReference.ConvertToCanonForm(CanonicalFormKind.Specific)); Assert.Same( referenceOverReference.ConvertToCanonForm(CanonicalFormKind.Universal), referenceOverReferenceOverReference.ConvertToCanonForm(CanonicalFormKind.Universal)); var threeParamReferenceOverS1R1S1 = _genericReferenceTypeWithThreeParams.MakeInstantiatedType( _structType, _referenceType, _structType); var threeParamReferenceOverS1R2S1 = _genericReferenceTypeWithThreeParams.MakeInstantiatedType( _structType, _otherReferenceType, _structType); var threeParamReferenceOverS1R2S2 = _genericReferenceTypeWithThreeParams.MakeInstantiatedType( _structType, _otherReferenceType, _otherStructType); Assert.Same( threeParamReferenceOverS1R1S1.ConvertToCanonForm(CanonicalFormKind.Specific), threeParamReferenceOverS1R2S1.ConvertToCanonForm(CanonicalFormKind.Specific)); Assert.Same( threeParamReferenceOverS1R1S1.ConvertToCanonForm(CanonicalFormKind.Universal), threeParamReferenceOverS1R2S1.ConvertToCanonForm(CanonicalFormKind.Universal)); Assert.Same( threeParamReferenceOverS1R1S1.ConvertToCanonForm(CanonicalFormKind.Universal), threeParamReferenceOverS1R2S2.ConvertToCanonForm(CanonicalFormKind.Universal)); // Universal canonical forms of reference type over reference and value types are equivalent var referenceOverStruct = _genericReferenceType.MakeInstantiatedType(_structType); var referenceOverOtherStruct = _genericReferenceType.MakeInstantiatedType(_otherStructType); Assert.Same( referenceOverStruct.ConvertToCanonForm(CanonicalFormKind.Universal), referenceOverOtherStruct.ConvertToCanonForm(CanonicalFormKind.Universal)); // Canon forms of reference type instantiated over a generic valuetype over any reference type var genericStructOverReference = _genericStructType.MakeInstantiatedType(_referenceType); var genericStructOverOtherReference = _genericStructType.MakeInstantiatedType(_otherReferenceType); var referenceOverGenericStructOverReference = _genericReferenceType.MakeInstantiatedType(genericStructOverReference); var referenceOverGenericStructOverOtherReference = _genericReferenceType.MakeInstantiatedType(genericStructOverOtherReference); Assert.Same( referenceOverGenericStructOverReference.ConvertToCanonForm(CanonicalFormKind.Specific), referenceOverGenericStructOverOtherReference.ConvertToCanonForm(CanonicalFormKind.Specific)); Assert.NotSame( referenceOverGenericStructOverReference.ConvertToCanonForm(CanonicalFormKind.Specific), referenceOverReference.ConvertToCanonForm(CanonicalFormKind.Specific)); Assert.Same( referenceOverGenericStructOverReference.ConvertToCanonForm(CanonicalFormKind.Universal), referenceOverGenericStructOverOtherReference.ConvertToCanonForm(CanonicalFormKind.Universal)); Assert.Same( referenceOverGenericStructOverReference.ConvertToCanonForm(CanonicalFormKind.Universal), referenceOverReference.ConvertToCanonForm(CanonicalFormKind.Universal)); // Canon of a type instantiated over a signature variable is the same type when just canonicalizing as specific, // but the universal canon form when performing universal canonicalization. var genericStructOverSignatureVariable = _genericStructType.MakeInstantiatedType(_context.GetSignatureVariable(0, false)); Assert.Same( genericStructOverSignatureVariable, genericStructOverSignatureVariable.ConvertToCanonForm(CanonicalFormKind.Specific)); Assert.NotSame( genericStructOverSignatureVariable, genericStructOverSignatureVariable.ConvertToCanonForm(CanonicalFormKind.Universal)); }