Пример #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));
                }
            }
        }
        private FieldInfo GetFieldInfo(RuntimeTypeHandle declaringTypeHandle, FieldHandle fieldHandle)
        {
            RuntimeTypeInfo      contextTypeInfo  = declaringTypeHandle.GetTypeForRuntimeTypeHandle();
            RuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers;
            MetadataReader       reader           = definingTypeInfo.Reader;

            return(RuntimeFieldInfo.GetRuntimeFieldInfo(fieldHandle, definingTypeInfo, contextTypeInfo));
        }
Пример #3
0
 //
 // propertyHandle - the "tkPropertyDef" that identifies the property.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created propertyHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimePropertyInfo(PropertyHandle propertyHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _propertyHandle = propertyHandle;
     _definingTypeInfo = definingTypeInfo;
     _contextTypeInfo = contextTypeInfo;
     _reader = definingTypeInfo.Reader;
     _property = propertyHandle.GetProperty(_reader);
 }
Пример #4
0
 //
 // propertyHandle - the "tkPropertyDef" that identifies the property.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created propertyHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimePropertyInfo(PropertyHandle propertyHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _propertyHandle   = propertyHandle;
     _definingTypeInfo = definingTypeInfo;
     _contextTypeInfo  = contextTypeInfo;
     _reader           = definingTypeInfo.Reader;
     _property         = propertyHandle.GetProperty(_reader);
 }
Пример #5
0
 //
 // fieldHandle    - the "tkFieldDef" that identifies the field.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created fieldHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimeFieldInfo(FieldHandle fieldHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _fieldHandle      = fieldHandle;
     _definingTypeInfo = definingTypeInfo;
     _contextTypeInfo  = contextTypeInfo;
     _reader           = definingTypeInfo.Reader;
     _field            = fieldHandle.GetField(_reader);
 }
Пример #6
0
 //
 // fieldHandle    - the "tkFieldDef" that identifies the field.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created fieldHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimeFieldInfo(FieldHandle fieldHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _fieldHandle = fieldHandle;
     _definingTypeInfo = definingTypeInfo;
     _contextTypeInfo = contextTypeInfo;
     _reader = definingTypeInfo.Reader;
     _field = fieldHandle.GetField(_reader);
 }
Пример #7
0
 //
 // eventHandle    - the "tkEventDef" that identifies the event.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created eventHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimeEventInfo(EventHandle eventHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _eventHandle      = eventHandle;
     _definingTypeInfo = definingTypeInfo;
     _contextTypeInfo  = contextTypeInfo;
     _reader           = definingTypeInfo.Reader;
     _event            = eventHandle.GetEvent(_reader);
 }
Пример #8
0
 //
 // eventHandle    - the "tkEventDef" that identifies the event.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created eventHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimeEventInfo(EventHandle eventHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _eventHandle = eventHandle;
     _definingTypeInfo = definingTypeInfo;
     _contextTypeInfo = contextTypeInfo;
     _reader = definingTypeInfo.Reader;
     _event = eventHandle.GetEvent(_reader);
 }
Пример #9
0
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 public RuntimeMethodCommon(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _definingTypeInfo = definingTypeInfo;
     _methodHandle     = methodHandle;
     _contextTypeInfo  = contextTypeInfo;
     _reader           = definingTypeInfo.Reader;
     _method           = methodHandle.GetMethod(_reader);
 }
Пример #10
0
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 public RuntimeMethodCommon(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _definingTypeInfo = definingTypeInfo;
     _methodHandle = methodHandle;
     _contextTypeInfo = contextTypeInfo;
     _reader = definingTypeInfo.Reader;
     _method = methodHandle.GetMethod(_reader);
 }
        private FieldInfo GetFieldInfo(RuntimeTypeHandle declaringTypeHandle, FieldHandle fieldHandle)
        {
            RuntimeTypeInfo      contextTypeInfo  = declaringTypeHandle.GetTypeForRuntimeTypeHandle();
            RuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers;
            MetadataReader       reader           = definingTypeInfo.Reader;

            // RuntimeFieldHandles always yield FieldInfo's whose ReflectedType equals the DeclaringType.
            RuntimeTypeInfo reflectedType = contextTypeInfo;

            return(RuntimeFieldInfo.GetRuntimeFieldInfo(fieldHandle, definingTypeInfo, contextTypeInfo, reflectedType));
        }
Пример #12
0
 internal static RuntimeEventInfo GetRuntimeEventInfo(EventHandle eventHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     return(new RuntimeEventInfo(eventHandle, definingTypeInfo, contextTypeInfo).WithDebugName());
 }
Пример #13
0
 internal static RuntimePropertyInfo GetRuntimePropertyInfo(PropertyHandle propertyHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     return(new RuntimePropertyInfo(propertyHandle, definingTypeInfo, contextTypeInfo).WithDebugName());
 }
Пример #14
0
        internal static RuntimeNamedMethodInfo GetRuntimeNamedMethodInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
        {
            RuntimeNamedMethodInfo method = new RuntimeNamedMethodInfo(methodHandle, definingTypeInfo, contextTypeInfo);

            method.WithDebugName();
            return(method);
        }
Пример #15
0
 internal static RuntimePlainConstructorInfo GetRuntimePlainConstructorInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     return(new RuntimePlainConstructorInfo(methodHandle, definingTypeInfo, contextTypeInfo));
 }
Пример #16
0
 internal static RuntimeFieldInfo GetRuntimeFieldInfo(FieldHandle fieldHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     return(new RuntimeFieldInfo(fieldHandle, definingTypeInfo, contextTypeInfo).WithDebugName());
 }
 internal RuntimeGenericParameterTypeForTypes(MetadataReader reader, GenericParameterHandle genericParameterHandle, RuntimeNamedTypeInfo declaringRuntimeNamedTypeInfo)
     : base(reader, genericParameterHandle)
 {
     _declaringRuntimeNamedTypeInfo = declaringRuntimeNamedTypeInfo;
 }
Пример #18
0
        private static String NonQualifiedTypeName(this Type type)
        {
            if (!type.IsRuntimeImplemented())
            {
                return(null);
            }

            RuntimeTypeInfo runtimeType = type.CastToRuntimeTypeInfo();

            if (runtimeType.HasElementType)
            {
                String elementTypeName = runtimeType.InternalRuntimeElementType.NonQualifiedTypeName();
                if (elementTypeName == null)
                {
                    return(null);
                }
                String suffix;
                if (runtimeType.IsArray)
                {
                    int rank = runtimeType.GetArrayRank();
                    if (rank == 1)
                    {
                        suffix = "[" + (runtimeType.IsMultiDimensionalArray ? "*" : "") + "]";
                    }
                    else
                    {
                        suffix = "[" + new String(',', rank - 1) + "]";
                    }
                }
                else if (runtimeType.IsByRef)
                {
                    suffix = "&";
                }
                else if (runtimeType.IsPointer)
                {
                    suffix = "*";
                }
                else
                {
                    return(null);
                }

                return(elementTypeName + suffix);
            }
            else if (runtimeType.IsGenericParameter)
            {
                return(null);
            }
            else if (runtimeType.IsConstructedGenericType)
            {
                StringBuilder sb = new StringBuilder();
                String        genericTypeDefinitionTypeName = runtimeType.GetGenericTypeDefinition().NonQualifiedTypeName();
                if (genericTypeDefinitionTypeName == null)
                {
                    return(null);
                }
                sb.Append(genericTypeDefinitionTypeName);
                sb.Append("[");
                String sep = "";
                foreach (RuntimeTypeInfo ga in runtimeType.InternalRuntimeGenericTypeArguments)
                {
                    String gaTypeName = ga.AssemblyQualifiedTypeName();
                    if (gaTypeName == null)
                    {
                        return(null);
                    }
                    sb.Append(sep + "[" + gaTypeName + "]");
                    sep = ",";
                }
                sb.Append("]");

                return(sb.ToString());
            }
            else
            {
                RuntimeNamedTypeInfo runtimeNamedTypeInfo = type.GetTypeInfo() as RuntimeNamedTypeInfo;
                if (runtimeNamedTypeInfo == null)
                {
                    return(null);
                }

                return(runtimeNamedTypeInfo.TraceableTypeName);
            }
        }
Пример #19
0
 //
 // Retrieves the unified Type object for a generic type parameter type.
 //
 internal static RuntimeType GetRuntimeGenericParameterTypeForTypes(RuntimeNamedTypeInfo typeOwner, GenericParameterHandle genericParameterHandle)
 {
     RuntimeGenericParameterTypeForTypes.UnificationKey key = new RuntimeGenericParameterTypeForTypes.UnificationKey(typeOwner.Reader, typeOwner.TypeDefinitionHandle, genericParameterHandle);
     return(GenericParameterTypeForTypesTable.Table.GetOrAdd(key).WithDebugName());
 }
Пример #20
0
        private static String NonQualifiedTypeName(this Type type)
        {
            RuntimeType runtimeType = type as RuntimeType;

            if (runtimeType == null)
            {
                return(null);
            }

            if (runtimeType.HasElementType)
            {
                String elementTypeName = runtimeType.InternalRuntimeElementType.NonQualifiedTypeName();
                if (elementTypeName == null)
                {
                    return(null);
                }
                String suffix;
                if (runtimeType.IsArray)
                {
                    int rank = runtimeType.GetArrayRank();
                    if (rank == 1)
                    {
                        suffix = "[" + (runtimeType.InternalIsMultiDimArray ? "*" : "") + "]";
                    }
                    else
                    {
                        suffix = "[" + new String(',', rank - 1) + "]";
                    }
                }
                else if (runtimeType.IsByRef)
                {
                    suffix = "&";
                }
                else if (runtimeType.IsPointer)
                {
                    suffix = "*";
                }
                else
                {
                    return(null);
                }

                return(elementTypeName + suffix);
            }
            else if (runtimeType.IsGenericParameter)
            {
                return(null);
            }
            else if (runtimeType.IsConstructedGenericType)
            {
                StringBuilder sb = new StringBuilder();
                String        genericTypeDefinitionTypeName = runtimeType.GetGenericTypeDefinition().NonQualifiedTypeName();
                if (genericTypeDefinitionTypeName == null)
                {
                    return(null);
                }
                sb.Append(genericTypeDefinitionTypeName);
                sb.Append("[");
                String sep = "";
                foreach (RuntimeType ga in runtimeType.InternalRuntimeGenericTypeArguments)
                {
                    String gaTypeName = ga.AssemblyQualifiedTypeName();
                    if (gaTypeName == null)
                    {
                        return(null);
                    }
                    sb.Append(sep + "[" + gaTypeName + "]");
                    sep = ",";
                }
                sb.Append("]");

                return(sb.ToString());
            }
            else
            {
                RuntimeNamedTypeInfo runtimeNamedTypeInfo = type.GetTypeInfo() as RuntimeNamedTypeInfo;
                if (runtimeNamedTypeInfo == null)
                {
                    return(null);
                }
                MetadataReader reader = runtimeNamedTypeInfo.Reader;

                String s = "";
                TypeDefinitionHandle      typeDefinitionHandle = runtimeNamedTypeInfo.TypeDefinitionHandle;
                NamespaceDefinitionHandle namespaceDefinitionHandle;
                do
                {
                    TypeDefinition typeDefinition = typeDefinitionHandle.GetTypeDefinition(reader);
                    String         name           = typeDefinition.Name.GetString(reader);
                    if (s == "")
                    {
                        s = name;
                    }
                    else
                    {
                        s = name + "+" + s;
                    }
                    namespaceDefinitionHandle = typeDefinition.NamespaceDefinition;
                    typeDefinitionHandle      = typeDefinition.EnclosingType;
                }while (!typeDefinitionHandle.IsNull(reader));

                NamespaceChain namespaceChain = new NamespaceChain(reader, namespaceDefinitionHandle);
                String         ns             = namespaceChain.NameSpace;
                if (ns != null)
                {
                    s = ns + "." + s;
                }
                return(s);
            }
        }
Пример #21
0
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimePlainConstructorInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _common = new RuntimeMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo);
 }
 internal RuntimeTypeInfo GetInspectionOnlyNamedRuntimeTypeInfo()
 {
     return(RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(_reader, _typeDefinitionHandle));
 }
Пример #23
0
            protected sealed override RuntimeGenericParameterTypeForTypes Factory(RuntimeGenericParameterTypeForTypes.UnificationKey key)
            {
                RuntimeNamedTypeInfo typeOwner = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(key.Reader, key.TypeDefinitionHandle);

                return(new RuntimeGenericParameterTypeForTypes(key.Reader, key.GenericParameterHandle, typeOwner));
            }
Пример #24
0
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimeNamedMethodInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
     : base()
 {
     _common = new RuntimeMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo);
 }
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimeNamedMethodInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
     : base()
 {
     _common = new RuntimeMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo);
 }
Пример #26
0
        //
        // Main routine to resolve a typeReference.
        //
        private static RuntimeType TryResolveTypeReference(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeReferenceHandle typeReferenceHandle, ref Exception exception)
        {
            {
                ExecutionDomain executionDomain = reflectionDomain as ExecutionDomain;
                if (executionDomain != null)
                {
                    RuntimeTypeHandle resolvedRuntimeTypeHandle;
                    if (executionDomain.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle))
                    {
                        return(ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(resolvedRuntimeTypeHandle));
                    }
                }
            }

            TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
            String        name          = typeReference.TypeName.GetString(reader);
            Handle        parent        = typeReference.ParentNamespaceOrType;
            HandleType    parentType    = parent.HandleType;
            TypeInfo      outerTypeInfo = null;

            // Check if this is a reference to a nested type.

            if (parentType == HandleType.TypeDefinition)
            {
                outerTypeInfo = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, parent.ToTypeDefinitionHandle(reader));
            }
            else if (parentType == HandleType.TypeReference)
            {
                RuntimeType outerType = reflectionDomain.TryResolveTypeReference(reader, parent.ToTypeReferenceHandle(reader), ref exception);
                if (outerType == null)
                {
                    return(null);
                }
                outerTypeInfo = outerType.GetTypeInfo();   // Since we got to outerType via a metadata reference, we're assured GetTypeInfo() won't throw a MissingMetadataException.
            }
            if (outerTypeInfo != null)
            {
                // It was a nested type. We've already resolved the containing type recursively - just find the nested among its direct children.
                TypeInfo resolvedTypeInfo = outerTypeInfo.GetDeclaredNestedType(name);
                if (resolvedTypeInfo == null)
                {
                    exception = reflectionDomain.CreateMissingMetadataException(outerTypeInfo, name);
                    return(null);
                }
                return((RuntimeType)(resolvedTypeInfo.AsType()));
            }


            // If we got here, the typeReference was to a non-nested type.
            if (parentType == HandleType.NamespaceReference)
            {
                AssemblyQualifiedTypeName assemblyQualifiedTypeName = parent.ToNamespaceReferenceHandle(reader).ToAssemblyQualifiedTypeName(name, reader);
                RuntimeType runtimeType;
                exception = assemblyQualifiedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out runtimeType);
                if (exception != null)
                {
                    return(null);
                }
                return(runtimeType);
            }

            throw new BadImageFormatException(); // Expected TypeReference parent to be typeRef, typeDef or namespaceRef.
        }
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private RuntimePlainConstructorInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _common = new RuntimeMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo);
 }
Пример #28
0
 public static RuntimeTypeInfo GetNamedType(this TypeDefinitionHandle typeDefinitionHandle, MetadataReader reader, RuntimeTypeHandle precomputedTypeHandle)
 {
     return(RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, typeDefinitionHandle, precomputedTypeHandle: precomputedTypeHandle));
 }