// // Retrieves the MethodBase for a given method handle. Helper to implement Delegate.GetMethodInfo() // public MethodBase GetMethod(RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, RuntimeTypeHandle[] genericMethodTypeArgumentHandles) { RuntimeTypeInfo contextTypeInfo = declaringTypeHandle.GetTypeForRuntimeTypeHandle(); RuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers; MetadataReader reader = definingTypeInfo.Reader; if (methodHandle.IsConstructor(reader)) { return(RuntimePlainConstructorInfo.GetRuntimePlainConstructorInfo(methodHandle, definingTypeInfo, contextTypeInfo)); } else { // RuntimeMethodHandles always yield methods whose ReflectedType is the DeclaringType. RuntimeTypeInfo reflectedType = contextTypeInfo; RuntimeNamedMethodInfo runtimeNamedMethodInfo = RuntimeNamedMethodInfo.GetRuntimeNamedMethodInfo(methodHandle, definingTypeInfo, contextTypeInfo, reflectedType); if (!runtimeNamedMethodInfo.IsGenericMethod) { return(runtimeNamedMethodInfo); } else { RuntimeTypeInfo[] genericTypeArguments = new RuntimeTypeInfo[genericMethodTypeArgumentHandles.Length]; for (int i = 0; i < genericMethodTypeArgumentHandles.Length; i++) { genericTypeArguments[i] = genericMethodTypeArgumentHandles[i].GetTypeForRuntimeTypeHandle(); } return(RuntimeConstructedGenericMethodInfo.GetRuntimeConstructedGenericMethodInfo(runtimeNamedMethodInfo, genericTypeArguments)); } } }
// // Retrieves the MethodBase for a given method handle. Helper to implement Delegate.GetMethodInfo() // public MethodBase GetMethod(RuntimeTypeHandle declaringTypeHandle, QMethodDefinition methodHandle, RuntimeTypeHandle[] genericMethodTypeArgumentHandles) { RuntimeTypeInfo contextTypeInfo = declaringTypeHandle.GetTypeForRuntimeTypeHandle(); RuntimeNamedMethodInfo?runtimeNamedMethodInfo = null; if (methodHandle.IsNativeFormatMetadataBased) { MethodHandle nativeFormatMethodHandle = methodHandle.NativeFormatHandle; NativeFormatRuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers.CastToNativeFormatRuntimeNamedTypeInfo(); MetadataReader reader = definingTypeInfo.Reader; if (nativeFormatMethodHandle.IsConstructor(reader)) { return(RuntimePlainConstructorInfo <NativeFormatMethodCommon> .GetRuntimePlainConstructorInfo(new NativeFormatMethodCommon(nativeFormatMethodHandle, definingTypeInfo, contextTypeInfo))); } else { // RuntimeMethodHandles always yield methods whose ReflectedType is the DeclaringType. RuntimeTypeInfo reflectedType = contextTypeInfo; runtimeNamedMethodInfo = RuntimeNamedMethodInfo <NativeFormatMethodCommon> .GetRuntimeNamedMethodInfo(new NativeFormatMethodCommon(nativeFormatMethodHandle, definingTypeInfo, contextTypeInfo), reflectedType); } } #if ECMA_METADATA_SUPPORT else { System.Reflection.Metadata.MethodDefinitionHandle ecmaFormatMethodHandle = methodHandle.EcmaFormatHandle; EcmaFormatRuntimeNamedTypeInfo definingEcmaTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers.CastToEcmaFormatRuntimeNamedTypeInfo(); System.Reflection.Metadata.MetadataReader reader = definingEcmaTypeInfo.Reader; if (ecmaFormatMethodHandle.IsConstructor(reader)) { return(RuntimePlainConstructorInfo <EcmaFormatMethodCommon> .GetRuntimePlainConstructorInfo(new EcmaFormatMethodCommon(ecmaFormatMethodHandle, definingEcmaTypeInfo, contextTypeInfo))); } else { // RuntimeMethodHandles always yield methods whose ReflectedType is the DeclaringType. RuntimeTypeInfo reflectedType = contextTypeInfo; runtimeNamedMethodInfo = RuntimeNamedMethodInfo <EcmaFormatMethodCommon> .GetRuntimeNamedMethodInfo(new EcmaFormatMethodCommon(ecmaFormatMethodHandle, definingEcmaTypeInfo, contextTypeInfo), reflectedType); } } #endif if (!runtimeNamedMethodInfo.IsGenericMethod || genericMethodTypeArgumentHandles == null) { return(runtimeNamedMethodInfo); } else { RuntimeTypeInfo[] genericTypeArguments = new RuntimeTypeInfo[genericMethodTypeArgumentHandles.Length]; for (int i = 0; i < genericMethodTypeArgumentHandles.Length; i++) { genericTypeArguments[i] = genericMethodTypeArgumentHandles[i].GetTypeForRuntimeTypeHandle(); } return(RuntimeConstructedGenericMethodInfo.GetRuntimeConstructedGenericMethodInfo(runtimeNamedMethodInfo, genericTypeArguments)); } }
// // Retrieves the MethodBase for a given method handle. Helper to implement Delegate.GetMethodInfo() // public MethodBase GetMethod(RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, RuntimeTypeHandle[] genericMethodTypeArgumentHandles) { RuntimeType declaringType = ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(declaringTypeHandle); RuntimeTypeInfo contextTypeInfo = declaringType.GetRuntimeTypeInfo(); RuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers; MetadataReader reader = definingTypeInfo.Reader; if (methodHandle.IsConstructor(reader)) { return RuntimePlainConstructorInfo.GetRuntimePlainConstructorInfo(methodHandle, definingTypeInfo, contextTypeInfo); } else { RuntimeNamedMethodInfo runtimeNamedMethodInfo = RuntimeNamedMethodInfo.GetRuntimeNamedMethodInfo(methodHandle, definingTypeInfo, contextTypeInfo); if (!runtimeNamedMethodInfo.IsGenericMethod) { return runtimeNamedMethodInfo; } else { RuntimeType[] genericTypeArguments = new RuntimeType[genericMethodTypeArgumentHandles.Length]; for (int i = 0; i < genericMethodTypeArgumentHandles.Length; i++) { genericTypeArguments[i] = ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(genericMethodTypeArgumentHandles[i]); } return RuntimeConstructedGenericMethodInfo.GetRuntimeConstructedGenericMethodInfo(runtimeNamedMethodInfo, genericTypeArguments); } } }