public TypeInfoCachedData(RuntimeTypeInfo runtimeTypeInfo) { _runtimeTypeInfo = runtimeTypeInfo; _methodLookupDispenser = new DispenserThatAlwaysReuses<String, RuntimeMethodInfo>(LookupDeclaredMethodByName); _fieldLookupDispenser = new DispenserThatAlwaysReuses<String, RuntimeFieldInfo>(LookupDeclaredFieldByName); _propertyLookupDispenser = new DispenserThatAlwaysReuses<String, RuntimePropertyInfo>(LookupDeclaredPropertyByName); _eventLookupDispenser = new DispenserThatAlwaysReuses<String, RuntimeEventInfo>(LookupDeclaredEventByName); }
internal IEnumerable<EventInfo> CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType) { RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers; if (definingType != null) { return definingType.CoreGetDeclaredEvents(optionalNameFilter, reflectedType, this); } return Empty<EventInfo>.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); }
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); } } foreach (RuntimeMethodInfo syntheticMethod in SyntheticMethods) { if (optionalNameFilter == null || optionalNameFilter.Matches(syntheticMethod.Name)) yield return syntheticMethod; } }
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, Array.Empty <RuntimeMethodInfo>())); return(definingType.CoreGetDeclaredMethods(optionalNameFilter, reflectedType, this)); } return(CoreGetDeclaredSyntheticMethods(optionalNameFilter)); }
// // Q: Why is the type handle part of the unification key when it doesn't participate in the Equals/HashCode computations? // A: It's a passenger. // // The typeHandle argument is "redundant" in that it can be computed from the rest of the key. However, we have callers (Type.GetTypeFromHandle()) that // already have the typeHandle so to avoid an unnecessary round-trip computation, we require the caller to pass it in separately. // We allow it to ride along in the key object because the ConcurrentUnifier classes we use don't support passing "extra" parameters to // their Factory methods. // public UnificationKey(RuntimeTypeInfo elementType, RuntimeTypeHandle typeHandle) { ElementType = elementType; TypeHandle = typeHandle; }
protected sealed override RuntimeGenericParameterTypeInfoForTypes Factory(UnificationKey key) { RuntimeTypeInfo typeOwner = key.TypeDefinitionHandle.GetNamedType(key.Reader); return(new RuntimeGenericParameterTypeInfoForTypes(key.Reader, key.GenericParameterHandle, typeOwner)); }
internal static RuntimeConstructedGenericTypeInfo GetRuntimeConstructedGenericTypeInfo(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments, RuntimeTypeHandle precomputedTypeHandle) { RuntimeTypeHandle typeHandle = precomputedTypeHandle.IsNull() ? GetRuntimeTypeHandleIfAny(genericTypeDefinition, genericTypeArguments) : precomputedTypeHandle; UnificationKey key = new UnificationKey(genericTypeDefinition, genericTypeArguments, typeHandle); RuntimeConstructedGenericTypeInfo typeInfo = ConstructedGenericTypeTable.Table.GetOrAdd(key); typeInfo.EstablishDebugName(); return(typeInfo); }
internal abstract IEnumerable<PropertyInfo> CoreGetDeclaredProperties(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo);
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)); } } } }
public PerNameQueryCache(RuntimeTypeInfo type, bool ignoreCase) { _type = type; _ignoreCase = ignoreCase; }
// Metadata providing implementations of RuntimeNamedTypeInfo implement the following methods // to provide filtered access to the various reflection objects by reading metadata directly. // The loop of examining methods is done in a metadata specific manner for greater efficiency. internal abstract IEnumerable<ConstructorInfo> CoreGetDeclaredConstructors(NameFilter optionalNameFilter, RuntimeTypeInfo contextTypeInfo);
internal abstract IEnumerable <PropertyInfo> CoreGetDeclaredProperties(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo);
internal abstract IEnumerable <FieldInfo> CoreGetDeclaredFields(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo);
// Metadata providing implementations of RuntimeNamedTypeInfo implement the following methods // to provide filtered access to the various reflection objects by reading metadata directly. // The loop of examining methods is done in a metadata specific manner for greater efficiency. internal abstract IEnumerable <ConstructorInfo> CoreGetDeclaredConstructors(NameFilter optionalNameFilter, RuntimeTypeInfo contextTypeInfo);
internal IEnumerable <EventInfo> CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType) { RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers; if (definingType != null) { return(definingType.CoreGetDeclaredEvents(optionalNameFilter, reflectedType, this)); } return(Empty <EventInfo> .Enumerable); }
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); } } }
// // Q: Why is the type handle part of the unification key when it doesn't participate in the Equals/HashCode computations? // A: It's a passenger. // // The typeHandle argument is "redundant" in that it can be computed from the rest of the key. However, we have callers (Type.GetTypeFromHandle()) that // already have the typeHandle so to avoid an unnecessary round-trip computation, we require the caller to pass it in separately. // We allow it to ride along in the key object because the ConcurrentUnifier classes we use don't support passing "extra" parameters to // their Factory methods. // public UnificationKey(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments, RuntimeTypeHandle typeHandle) { GenericTypeDefinition = genericTypeDefinition; GenericTypeArguments = genericTypeArguments; TypeHandle = typeHandle; }
internal IEnumerable <FieldInfo> CoreGetDeclaredFields(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType) { RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers; if (definingType != null) { return(definingType.CoreGetDeclaredFields(optionalNameFilter, reflectedType, this)); } return(Array.Empty <FieldInfo>()); }
internal abstract IEnumerable<FieldInfo> CoreGetDeclaredFields(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo);
internal static RuntimeArrayTypeInfo GetArrayTypeInfo(RuntimeTypeInfo elementType, bool multiDim, int rank) { return(GetArrayTypeInfo(elementType, multiDim, rank, GetRuntimeTypeHandleIfAny(elementType, multiDim, rank))); }
internal static RuntimeByRefTypeInfo GetByRefTypeInfo(RuntimeTypeInfo elementType) { return(GetByRefTypeInfo(elementType, GetRuntimeTypeHandleIfAny(elementType))); }
internal static RuntimePointerTypeInfo GetPointerTypeInfo(RuntimeTypeInfo elementType) { return(GetPointerTypeInfo(elementType, precomputedTypeHandle: GetRuntimeTypeHandleIfAny(elementType))); }
private RuntimeGenericParameterTypeInfoForTypes(MetadataReader reader, GenericParameterHandle genericParameterHandle, RuntimeTypeInfo declaringRuntimeNamedTypeInfo) : base(reader, genericParameterHandle) { _declaringRuntimeNamedTypeInfo = declaringRuntimeNamedTypeInfo; }
internal static RuntimeConstructedGenericTypeInfo GetRuntimeConstructedGenericTypeInfo(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments) { return(GetRuntimeConstructedGenericTypeInfo(genericTypeDefinition, genericTypeArguments, precomputedTypeHandle: GetRuntimeTypeHandleIfAny(genericTypeDefinition, genericTypeArguments))); }
internal sealed override MethodInvoker GetUncachedMethodInvoker(RuntimeTypeInfo[] methodArguments, MemberInfo exceptionPertainant) { throw NotImplemented.ByDesign; }
public sealed override Type MakeGenericType(params Type[] typeArguments) { #if ENABLE_REFLECTION_TRACE if (ReflectionTrace.Enabled) { ReflectionTrace.TypeInfo_MakeGenericType(this, typeArguments); } #endif if (typeArguments == null) { throw new ArgumentNullException(nameof(typeArguments)); } if (!IsGenericTypeDefinition) { throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this)); } // We intentionally don't validate the number of arguments or their suitability to the generic type's constraints. // In a pay-for-play world, this can cause needless MissingMetadataExceptions. There is no harm in creating // the Type object for an inconsistent generic type - no EEType will ever match it so any attempt to "invoke" it // will throw an exception. bool foundSignatureType = false; RuntimeTypeInfo[] runtimeTypeArguments = new RuntimeTypeInfo[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { RuntimeTypeInfo runtimeTypeArgument = runtimeTypeArguments[i] = typeArguments[i] as RuntimeTypeInfo; if (runtimeTypeArgument == null) { if (typeArguments[i] == null) { throw new ArgumentNullException(); } if (typeArguments[i].IsSignatureType) { foundSignatureType = true; } else { throw new PlatformNotSupportedException(SR.PlatformNotSupported_MakeGenericType); // "PlatformNotSupported" because on desktop, passing in a foreign type is allowed and creates a RefEmit.TypeBuilder } } } if (foundSignatureType) { return(ReflectionAugments.MakeGenericSignatureType(this, typeArguments)); } for (int i = 0; i < typeArguments.Length; i++) { RuntimeTypeInfo runtimeTypeArgument = runtimeTypeArguments[i]; // Desktop compatibility: Treat generic type definitions as a constructed generic type using the generic parameters as type arguments. if (runtimeTypeArgument.IsGenericTypeDefinition) { runtimeTypeArgument = runtimeTypeArguments[i] = runtimeTypeArgument.GetConstructedGenericType(runtimeTypeArgument.RuntimeGenericTypeParameters); } if (runtimeTypeArgument.IsByRefLike) { throw new TypeLoadException(SR.CannotUseByRefLikeTypeInInstantiation); } } return(this.GetConstructedGenericType(runtimeTypeArguments)); }
internal IEnumerable<EventInfo> CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType) { RuntimeNamedTypeInfo definingType = AnchoringTypeDefinitionForDeclaredMembers; if (definingType != null) { MetadataReader reader = definingType.Reader; foreach (EventHandle eventHandle in definingType.DeclaredEventHandles) { if (optionalNameFilter == null || optionalNameFilter.Matches(eventHandle.GetEvent(reader).Name, reader)) yield return RuntimeEventInfo.GetRuntimeEventInfo(eventHandle, definingType, this); } } }
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); } } }