/// <summary> /// Resolve a virtual function call (to a virtual method, not an interface method) /// </summary> /// <param name="targetMethod"></param> /// <param name="objectType"></param> /// <returns>The override of the virtual method that should be called</returns> private static MethodDesc FindVirtualFunctionTargetMethodOnObjectType(MethodDesc targetMethod, MetadataType objectType) { // Step 1, convert objectType to uninstantiated form MetadataType uninstantiatedType = objectType; MethodDesc initialTargetMethod = targetMethod; InstantiatedType initialInstantiatedType = objectType as InstantiatedType; if (initialInstantiatedType != null) { uninstantiatedType = (MetadataType)initialInstantiatedType.GetTypeDefinition(); } // Step 2, convert targetMethod to method in type hierarchy of uninstantiated form targetMethod = targetMethod.GetMethodDefinition(); if (uninstantiatedType != objectType) { targetMethod = uninstantiatedType.FindMethodOnTypeWithMatchingTypicalMethod(targetMethod); } // Step 3, find unification group of target method UnificationGroup group = new UnificationGroup(FindSlotDefiningMethodForVirtualMethod(targetMethod)); FindBaseUnificationGroup(uninstantiatedType, group); // Step 4, name/sig match virtual function resolve MethodDesc resolutionTarget = FindNameSigOverrideForVirtualMethod(group.DefiningMethod, uninstantiatedType); if (resolutionTarget == null) { return(null); } // Step 5, convert resolution target from uninstantiated form target to objecttype target, // and instantiate as appropriate if (uninstantiatedType != objectType) { resolutionTarget = objectType.FindMethodOnTypeWithMatchingTypicalMethod(resolutionTarget); } if (initialTargetMethod.HasInstantiation) { resolutionTarget = resolutionTarget.MakeInstantiatedMethod(initialTargetMethod.Instantiation); } return(resolutionTarget); }