Beispiel #1
0
        internal IEnumerable <MethodInfo> CoreGetDeclaredMethods(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType)
        {
            RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers;

            if (definingType != null)
            {
                MetadataReader reader = definingType.Reader;
                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(RuntimeNamedMethodInfo.GetRuntimeNamedMethodInfo(methodHandle, definingType, this, reflectedType));
                    }
                }
            }

            foreach (RuntimeMethodInfo syntheticMethod in SyntheticMethods)
            {
                if (optionalNameFilter == null || optionalNameFilter.Matches(syntheticMethod.Name))
                {
                    yield return(syntheticMethod);
                }
            }
        }
Beispiel #2
0
        //
        // Return all declared methods whose name matches "optionalNameFilter". If optionalNameFilter is null, return them all.
        //
        internal IEnumerable <RuntimeMethodInfo> GetDeclaredMethodsInternal(RuntimeNamedTypeInfo definingType, String optionalNameFilter)
        {
            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));

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

                    if ((optionalNameFilter != null) && !method.Name.StringEquals(optionalNameFilter, reader))
                    {
                        continue;
                    }

                    if (MetadataReaderExtensions.IsConstructor(ref method, reader))
                    {
                        continue;
                    }
                    yield return(RuntimeNamedMethodInfo.GetRuntimeNamedMethodInfo(methodHandle, definingType, this));
                }
            }

            foreach (RuntimeMethodInfo syntheticMethod in SyntheticMethods)
            {
                if (optionalNameFilter == null || optionalNameFilter == syntheticMethod.Name)
                {
                    yield return(syntheticMethod);
                }
            }
        }
Beispiel #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);
 }
Beispiel #4
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);
 }
Beispiel #5
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);
 }
Beispiel #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);
 }
Beispiel #7
0
 private static RuntimeTypeInfo CreateRuntimeTypeInfo(RuntimeType runtimeType)
 {
     if (runtimeType.HasElementType)
     {
         if (runtimeType.IsArray)
         {
             return(RuntimeArrayTypeInfo.GetRuntimeArrayTypeInfo(runtimeType));
         }
         else
         {
             return(RuntimeHasElementTypeInfo.GetRuntimeHasElementypeInfo(runtimeType));
         }
     }
     else if (runtimeType.IsConstructedGenericType)
     {
         RuntimeTypeHandle typeHandle;
         if (runtimeType.InternalTryGetTypeHandle(out typeHandle) && ReflectionCoreExecution.ExecutionEnvironment.IsReflectionBlocked(typeHandle))
         {
             return(RuntimeBlockedTypeInfo.GetRuntimeBlockedTypeInfo(runtimeType));
         }
         return(RuntimeConstructedGenericTypeInfo.GetRuntimeConstructedGenericTypeInfo(runtimeType));
     }
     else
     {
         RuntimeInspectionOnlyNamedType inspectionOnlyNamedType = runtimeType as RuntimeInspectionOnlyNamedType;
         if (inspectionOnlyNamedType != null)
         {
             return(inspectionOnlyNamedType.GetInspectionOnlyNamedRuntimeTypeInfo());
         }
         else
         {
             RuntimeGenericParameterType genericParameterType = runtimeType as RuntimeGenericParameterType;
             if (genericParameterType != null)
             {
                 return(RuntimeGenericParameterTypeInfo.GetRuntimeGenericParameterTypeInfo(genericParameterType));
             }
             else
             {
                 MetadataReader       reader;
                 TypeDefinitionHandle typeDefHandle;
                 if (ReflectionCoreExecution.ExecutionEnvironment.TryGetMetadataForNamedType(runtimeType.TypeHandle, out reader, out typeDefHandle))
                 {
                     return(RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, typeDefHandle));
                 }
                 if (ReflectionCoreExecution.ExecutionEnvironment.IsReflectionBlocked(runtimeType.TypeHandle))
                 {
                     return(RuntimeBlockedTypeInfo.GetRuntimeBlockedTypeInfo(runtimeType));
                 }
                 else
                 {
                     return(RuntimeNoMetadataNamedTypeInfo.GetRuntimeNoMetadataNamedTypeInfo(runtimeType));
                 }
             }
         }
     }
 }
Beispiel #8
0
        internal IEnumerable <EventInfo> CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType)
        {
            RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers;

            if (definingType != null)
            {
                return(definingType.CoreGetDeclaredEvents(optionalNameFilter, reflectedType, this));
            }
            return(Array.Empty <EventInfo>());
        }
        internal IEnumerable <FieldInfo> CoreGetDeclaredFields(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType)
        {
            RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers;

            if (definingType != null)
            {
                return(definingType.CoreGetDeclaredFields(optionalNameFilter, reflectedType, this));
            }
            return(Empty <FieldInfo> .Enumerable);
        }
        internal IEnumerable <MethodInfo> CoreGetDeclaredMethods(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType)
        {
            RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers;

            if (definingType != null)
            {
                // If there is a definingType, we do not support Synthetic constructors
                Debug.Assert(object.ReferenceEquals(SyntheticMethods, Empty <RuntimeMethodInfo> .Enumerable));

                return(definingType.CoreGetDeclaredMethods(optionalNameFilter, reflectedType, this));
            }

            return(CoreGetDeclaredSyntheticMethods(optionalNameFilter));
        }
Beispiel #11
0
        internal IEnumerable <PropertyInfo> CoreGetDeclaredProperties(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType)
        {
            RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers;

            if (definingType != null)
            {
                MetadataReader reader = definingType.Reader;
                foreach (PropertyHandle propertyHandle in definingType.DeclaredPropertyHandles)
                {
                    if (optionalNameFilter == null || optionalNameFilter.Matches(propertyHandle.GetProperty(reader).Name, reader))
                    {
                        yield return(RuntimePropertyInfo.GetRuntimePropertyInfo(propertyHandle, definingType, this, reflectedType));
                    }
                }
            }
        }
Beispiel #12
0
        private RuntimeFieldInfo LookupDeclaredFieldByName(String name)
        {
            RuntimeNamedTypeInfo           definingType = _runtimeTypeInfo.AnchoringTypeDefinitionForDeclaredMembers;
            IEnumerator <RuntimeFieldInfo> matches      = _runtimeTypeInfo.GetDeclaredFieldsInternal(definingType, name).GetEnumerator();

            if (!matches.MoveNext())
            {
                return(null);
            }
            RuntimeFieldInfo result = matches.Current;

            if (matches.MoveNext())
            {
                throw new AmbiguousMatchException();
            }
            return(result);
        }
Beispiel #13
0
        //
        // Return all declared properties whose name matches "optionalNameFilter". If optionalNameFilter is null, return them all.
        //
        internal IEnumerable <RuntimePropertyInfo> GetDeclaredPropertiesInternal(RuntimeNamedTypeInfo definingType, String optionalNameFilter)
        {
            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));

                MetadataReader reader = definingType.Reader;
                foreach (PropertyHandle propertyHandle in definingType.DeclaredPropertyHandles)
                {
                    if (optionalNameFilter == null || propertyHandle.GetProperty(reader).Name.StringEquals(optionalNameFilter, reader))
                    {
                        yield return(RuntimePropertyInfo.GetRuntimePropertyInfo(propertyHandle, definingType, this));
                    }
                }
            }
        }
Beispiel #14
0
        internal static RuntimeNamedTypeInfo GetRuntimeNamedTypeInfo(MetadataReader metadataReader, TypeDefinitionHandle typeDefHandle, RuntimeTypeHandle precomputedTypeHandle)
        {
            RuntimeTypeHandle typeHandle = precomputedTypeHandle;

            if (typeHandle.IsNull())
            {
                if (!ReflectionCoreExecution.ExecutionEnvironment.TryGetNamedTypeForMetadata(metadataReader, typeDefHandle, out typeHandle))
                {
                    typeHandle = default(RuntimeTypeHandle);
                }
            }
            UnificationKey key = new UnificationKey(metadataReader, typeDefHandle, typeHandle);

            RuntimeNamedTypeInfo type = NamedTypeTable.Table.GetOrAdd(key);

            type.EstablishDebugName();
            return(type);
        }
        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)
            {
                // If there is a definingType, we do not support Synthetic constructors
                Debug.Assert(object.ReferenceEquals(SyntheticConstructors, Empty <RuntimeConstructorInfo> .Enumerable));

                return(definingType.CoreGetDeclaredConstructors(optionalNameFilter, this));
            }

            return(CoreGetDeclaredSyntheticConstructors(optionalNameFilter));
        }
Beispiel #16
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);
            }
        }
Beispiel #17
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);
                }
            }
        }
Beispiel #18
0
        //
        // For app-compat reasons, we need to make sure that only TypeInfo instance exists for a given semantic type. If you change this, you must change the way
        // RuntimeTypeInfo.Equals() is implemented.
        //
        internal static RuntimeGenericParameterTypeInfoForTypes GetRuntimeGenericParameterTypeInfoForTypes(RuntimeNamedTypeInfo typeOwner, GenericParameterHandle genericParameterHandle)
        {
            UnificationKey key = new UnificationKey(typeOwner.Reader, typeOwner.TypeDefinitionHandle, genericParameterHandle);
            RuntimeGenericParameterTypeInfoForTypes type = GenericParameterTypeForTypesTable.Table.GetOrAdd(key);

            type.EstablishDebugName();
            return(type);
        }
Beispiel #19
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;
            }
        }
Beispiel #20
0
        //
        // Return all declared properties whose name matches "optionalNameFilter". If optionalNameFilter is null, return them all.
        //
        internal IEnumerable<RuntimePropertyInfo> GetDeclaredPropertiesInternal(RuntimeNamedTypeInfo definingType, String optionalNameFilter)
        {
            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));

                MetadataReader reader = definingType.Reader;
                foreach (PropertyHandle propertyHandle in definingType.DeclaredPropertyHandles)
                {
                    if (optionalNameFilter == null || propertyHandle.GetProperty(reader).Name.StringEquals(optionalNameFilter, reader))
                        yield return RuntimePropertyInfo.GetRuntimePropertyInfo(propertyHandle, definingType, this);
                }
            }
        }
Beispiel #21
0
        //
        // Return all declared methods whose name matches "optionalNameFilter". If optionalNameFilter is null, return them all.
        //
        internal IEnumerable<RuntimeMethodInfo> GetDeclaredMethodsInternal(RuntimeNamedTypeInfo definingType, String optionalNameFilter)
        {
            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));

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

                    if ((optionalNameFilter != null) && !method.Name.StringEquals(optionalNameFilter, reader))
                        continue;

                    if (MetadataReaderExtensions.IsConstructor(ref method, reader))
                        continue;
                    yield return RuntimeNamedMethodInfo.GetRuntimeNamedMethodInfo(methodHandle, definingType, this);
                }
            }

            foreach (RuntimeMethodInfo syntheticMethod in SyntheticMethods)
            {
                if (optionalNameFilter == null || optionalNameFilter == syntheticMethod.Name)
                {
                    yield return syntheticMethod;
                }
            }
        }
Beispiel #22
0
 protected sealed override Tuple <Guid> Factory(RuntimeNamedTypeInfo key)
 {
     return(new Tuple <Guid>(Guid.NewGuid()));
 }
 //
 // 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);
 }
 //
 // 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);
 }