public MethodDesc GetMethod(Internal.Metadata.NativeFormat.Handle token) { MethodDesc method = _metadataUnit.GetMethod(token, null); MethodDesc instantiatedMethod = method.InstantiateSignature(TypeInstantiation, MethodInstantiation); return(instantiatedMethod); }
/// <summary> /// Attempt a virtual dispatch on a given instanceType based on the method found via a metadata token /// </summary> private static bool TryDispatchMethodOnTarget_Inner(NativeFormatModuleInfo module, int metadataToken, RuntimeTypeHandle targetInstanceType, out IntPtr methodAddress) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING TypeSystemContext context = TypeSystemContextFactory.Create(); NativeFormatMetadataUnit metadataUnit = context.ResolveMetadataUnit(module); MethodDesc targetMethod = metadataUnit.GetMethod(metadataToken.AsHandle(), null); TypeDesc instanceType = context.ResolveRuntimeTypeHandle(targetInstanceType); MethodDesc realTargetMethod = targetMethod; // For non-interface methods we support the target method not being the exact target. (This allows // a canonical method to be passed in and work for any generic type instantiation.) if (!targetMethod.OwningType.IsInterface) { realTargetMethod = instanceType.FindMethodOnTypeWithMatchingTypicalMethod(targetMethod); } bool success = LazyVTableResolver.TryDispatchMethodOnTarget(instanceType, realTargetMethod, out methodAddress); TypeSystemContextFactory.Recycle(context); return(success); #else methodAddress = IntPtr.Zero; return(false); #endif }