Example #1
0
        //
        // 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));
                }
            }
        }
Example #2
0
        //
        // 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));
            }
        }
Example #3
0
        //
        // Return all declared constructors.
        //
        private IEnumerable <RuntimeConstructorInfo> GetDeclaredConstructorsInternal(RuntimeNamedTypeInfo definingType)
        {
            if (definingType != null)
            {
                // We require the caller to pass a value that we could calculate ourselves because we're an iterator and we
                // don't want any MissingMetadataException that AnchoringType throws to be deferred.
                Debug.Assert(definingType.Equals(this.AnchoringTypeDefinitionForDeclaredMembers));

                RuntimeTypeInfo contextType = this;
                foreach (MethodHandle methodHandle in definingType.DeclaredConstructorHandles)
                {
                    yield return(RuntimePlainConstructorInfo.GetRuntimePlainConstructorInfo(methodHandle, definingType, contextType));
                }
            }

            foreach (RuntimeConstructorInfo syntheticConstructor in SyntheticConstructors)
            {
                yield return(syntheticConstructor);
            }
        }
Example #4
0
        internal IEnumerable <ConstructorInfo> CoreGetDeclaredConstructors(NameFilter optionalNameFilter)
        {
            //
            // - It may sound odd to get a non-null name filter for a constructor search, but Type.GetMember() is an api that does this.
            //
            // - All GetConstructor() apis act as if BindingFlags.DeclaredOnly were specified. So the ReflectedType will always be the declaring type and so is not passed to this method.
            //
            RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers;

            if (definingType != null)
            {
                MetadataReader  reader      = definingType.Reader;
                RuntimeTypeInfo contextType = this;
                foreach (MethodHandle methodHandle in definingType.DeclaredMethodAndConstructorHandles)
                {
                    Method method = methodHandle.GetMethod(reader);

                    if (!MetadataReaderExtensions.IsConstructor(ref method, reader))
                    {
                        continue;
                    }

                    if (optionalNameFilter == null || optionalNameFilter.Matches(method.Name, reader))
                    {
                        yield return(RuntimePlainConstructorInfo.GetRuntimePlainConstructorInfo(methodHandle, definingType, contextType));
                    }
                }
            }

            foreach (RuntimeConstructorInfo syntheticConstructor in SyntheticConstructors)
            {
                if (optionalNameFilter == null || optionalNameFilter.Matches(syntheticConstructor.IsStatic ? ConstructorInfo.TypeConstructorName : ConstructorInfo.ConstructorName))
                {
                    yield return(syntheticConstructor);
                }
            }
        }
        internal sealed override IEnumerable <ConstructorInfo> CoreGetDeclaredConstructors(NameFilter optionalNameFilter, RuntimeTypeInfo contextTypeInfo)
        {
            //
            // - It may sound odd to get a non-null name filter for a constructor search, but Type.GetMember() is an api that does this.
            //
            // - All GetConstructor() apis act as if BindingFlags.DeclaredOnly were specified. So the ReflectedType will always be the declaring type and so is not passed to this method.
            //
            MetadataReader reader = Reader;

            foreach (MethodHandle methodHandle in DeclaredMethodAndConstructorHandles)
            {
                Method method = methodHandle.GetMethod(reader);

                if (!NativeFormatMetadataReaderExtensions.IsConstructor(ref method, reader))
                {
                    continue;
                }

                if (optionalNameFilter == null || optionalNameFilter.Matches(method.Name, reader))
                {
                    yield return(RuntimePlainConstructorInfo <NativeFormatMethodCommon> .GetRuntimePlainConstructorInfo(new NativeFormatMethodCommon(methodHandle, this, contextTypeInfo)));
                }
            }
        }