1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Diagnostics; 6 using System.Collections.Generic; 7 using System.Reflection.Runtime.General; 8 using System.Reflection.Runtime.MethodInfos; 9 using System.Reflection.Runtime.MethodInfos.NativeFormat; 10 using System.Reflection.Runtime.FieldInfos.NativeFormat; 11 using System.Reflection.Runtime.PropertyInfos.NativeFormat; 12 using System.Reflection.Runtime.EventInfos.NativeFormat; 13 using NameFilter = System.Reflection.Runtime.BindingFlagSupport.NameFilter; 14 15 using Internal.Metadata.NativeFormat; 16 17 namespace System.Reflection.Runtime.TypeInfos.NativeFormat 18 { 19 internal sealed partial class NativeFormatRuntimeNamedTypeInfo 20 { CoreGetDeclaredConstructors(NameFilter optionalNameFilter, RuntimeTypeInfo contextTypeInfo)21 internal sealed override IEnumerable<ConstructorInfo> CoreGetDeclaredConstructors(NameFilter optionalNameFilter, RuntimeTypeInfo contextTypeInfo) 22 { 23 // 24 // - It may sound odd to get a non-null name filter for a constructor search, but Type.GetMember() is an api that does this. 25 // 26 // - 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. 27 // 28 MetadataReader reader = Reader; 29 foreach (MethodHandle methodHandle in DeclaredMethodAndConstructorHandles) 30 { 31 Method method = methodHandle.GetMethod(reader); 32 33 if (!NativeFormatMetadataReaderExtensions.IsConstructor(ref method, reader)) 34 continue; 35 36 if (optionalNameFilter == null || optionalNameFilter.Matches(method.Name, reader)) 37 yield return RuntimePlainConstructorInfo<NativeFormatMethodCommon>.GetRuntimePlainConstructorInfo(new NativeFormatMethodCommon(methodHandle, this, contextTypeInfo)); 38 } 39 } 40 CoreGetDeclaredMethods(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo)41 internal sealed override IEnumerable<MethodInfo> CoreGetDeclaredMethods(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo) 42 { 43 MetadataReader reader = Reader; 44 foreach (MethodHandle methodHandle in DeclaredMethodAndConstructorHandles) 45 { 46 Method method = methodHandle.GetMethod(reader); 47 48 if (NativeFormatMetadataReaderExtensions.IsConstructor(ref method, reader)) 49 continue; 50 51 if (optionalNameFilter == null || optionalNameFilter.Matches(method.Name, reader)) 52 yield return RuntimeNamedMethodInfo<NativeFormatMethodCommon>.GetRuntimeNamedMethodInfo(new NativeFormatMethodCommon(methodHandle, this, contextTypeInfo), reflectedType); 53 } 54 } 55 CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo)56 internal sealed override IEnumerable<EventInfo> CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo) 57 { 58 MetadataReader reader = Reader; 59 foreach (EventHandle eventHandle in DeclaredEventHandles) 60 { 61 if (optionalNameFilter == null || optionalNameFilter.Matches(eventHandle.GetEvent(reader).Name, reader)) 62 yield return NativeFormatRuntimeEventInfo.GetRuntimeEventInfo(eventHandle, this, contextTypeInfo, reflectedType); 63 } 64 } 65 CoreGetDeclaredFields(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo)66 internal sealed override IEnumerable<FieldInfo> CoreGetDeclaredFields(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo) 67 { 68 MetadataReader reader = Reader; 69 foreach (FieldHandle fieldHandle in DeclaredFieldHandles) 70 { 71 if (optionalNameFilter == null || optionalNameFilter.Matches(fieldHandle.GetField(reader).Name, reader)) 72 yield return NativeFormatRuntimeFieldInfo.GetRuntimeFieldInfo(fieldHandle, this, contextTypeInfo, reflectedType); 73 } 74 } 75 CoreGetDeclaredProperties(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo)76 internal sealed override IEnumerable<PropertyInfo> CoreGetDeclaredProperties(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo) 77 { 78 MetadataReader reader = Reader; 79 foreach (PropertyHandle propertyHandle in DeclaredPropertyHandles) 80 { 81 if (optionalNameFilter == null || optionalNameFilter.Matches(propertyHandle.GetProperty(reader).Name, reader)) 82 yield return NativeFormatRuntimePropertyInfo.GetRuntimePropertyInfo(propertyHandle, this, contextTypeInfo, reflectedType); 83 } 84 } 85 CoreGetDeclaredNestedTypes(NameFilter optionalNameFilter)86 internal sealed override IEnumerable<Type> CoreGetDeclaredNestedTypes(NameFilter optionalNameFilter) 87 { 88 foreach (TypeDefinitionHandle nestedTypeHandle in _typeDefinition.NestedTypes) 89 { 90 if (optionalNameFilter == null || optionalNameFilter.Matches(nestedTypeHandle.GetTypeDefinition(_reader).Name, _reader)) 91 yield return nestedTypeHandle.GetNamedType(_reader); 92 } 93 } 94 } 95 } 96