static partial void TryGetFullNameFromTypeDefEcma(QTypeDefinition qTypeDefinition, List <int> genericParameterOffsets, ref string result) { result = null; if (!qTypeDefinition.IsEcmaFormatMetadataBased) { return; } MetadataReader reader = qTypeDefinition.EcmaFormatReader; TypeDefinition typeDefinition = reader.GetTypeDefinition(qTypeDefinition.EcmaFormatHandle); result = reader.GetString(typeDefinition.Name); TypeDefinitionHandle enclosingTypeHandle = typeDefinition.GetDeclaringType(); if (!enclosingTypeHandle.IsNil) { String containingTypeName = null; TryGetFullNameFromTypeDefEcma(new QTypeDefinition(reader, enclosingTypeHandle), genericParameterOffsets, ref containingTypeName); result = containingTypeName + "." + result; } else { if (!typeDefinition.Namespace.IsNil) { string namespaceName = reader.GetString(typeDefinition.Namespace); result = namespaceName + "." + result; } } result = ConvertBackTickNameToNameWithReducerInputFormat(result, genericParameterOffsets); }
private static string EcmaMetadataFullName(QTypeDefinition qTypeDefinition) { if (!qTypeDefinition.IsEcmaFormatMetadataBased) { return(null); } MetadataReader reader = qTypeDefinition.EcmaFormatReader; TypeDefinition typeDefinition = reader.GetTypeDefinition(qTypeDefinition.EcmaFormatHandle); string result = reader.GetString(typeDefinition.Name); TypeDefinitionHandle enclosingTypeHandle = typeDefinition.GetDeclaringType(); if (!enclosingTypeHandle.IsNil) { String containingTypeName = EcmaMetadataFullName(new QTypeDefinition(reader, enclosingTypeHandle)); result = containingTypeName + "." + result; } else { if (!typeDefinition.Namespace.IsNil) { string namespaceName = reader.GetString(typeDefinition.Namespace); result = namespaceName + "." + result; } } return(result); }
/// <summary> /// Return the RuntimeTypeHandle for the named type described in metadata. This is used to implement the Create and Invoke /// apis for types. /// /// Preconditions: /// metadataReader + typeDefHandle - a valid metadata reader + typeDefinitionHandle where "metadataReader" is one /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders. /// /// Note: Although this method has a "bool" return value like the other mapping table accessors, the Project N pay-for-play design /// guarantees that any type enabled for metadata also has a RuntimeTypeHandle underneath. /// </summary> /// <param name="metadataReader">Metadata reader for module containing the type</param> /// <param name="typeDefHandle">TypeDef handle for the type to look up</param> /// <param name="runtimeTypeHandle">Runtime type handle (EEType) for the given type</param> public unsafe bool TryGetNamedTypeForMetadata(QTypeDefinition qTypeDefinition, out RuntimeTypeHandle runtimeTypeHandle) { runtimeTypeHandle = default(RuntimeTypeHandle); NamedTypeLookupResult result = _metadataToRuntimeTypeHandleHashtable.GetOrCreateValue(qTypeDefinition); if (result.VersionNumber <= _namedTypeLookupLiveVersion) { runtimeTypeHandle = result.RuntimeTypeHandle; } return(!runtimeTypeHandle.IsNull()); }
public void UnregisterNewNamedTypeRuntimeTypeHandle(QTypeDefinition qTypeDefinition, RuntimeTypeHandle runtimeTypeHandle) { NamedTypeLookupResult metadataLookupResult; if (_metadataToRuntimeTypeHandleHashtable.TryGetValue(qTypeDefinition, out metadataLookupResult)) { metadataLookupResult.RuntimeTypeHandle = default(RuntimeTypeHandle); metadataLookupResult.VersionNumber = -1; } if (_runtimeTypeHandleToMetadataHashtable.TryGetValue(runtimeTypeHandle, out _)) { metadataLookupResult.GcStaticFields = IntPtr.Zero; metadataLookupResult.NonGcStaticFields = IntPtr.Zero; metadataLookupResult.RuntimeTypeHandle = default(RuntimeTypeHandle); } }
public unsafe bool TryGetOrCreateNamedTypeForMetadata( QTypeDefinition qTypeDefinition, out RuntimeTypeHandle runtimeTypeHandle) { if (TryGetNamedTypeForMetadata(qTypeDefinition, out runtimeTypeHandle)) { return true; } #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING using (LockHolder.Hold(_typeLoaderLock)) { IntPtr runtimeTypeHandleAsIntPtr; TypeBuilder.ResolveSingleTypeDefinition(qTypeDefinition, out runtimeTypeHandleAsIntPtr); runtimeTypeHandle = *(RuntimeTypeHandle*)&runtimeTypeHandleAsIntPtr; return true; } #else return false; #endif }
public void RegisterNewNamedTypeRuntimeTypeHandle(QTypeDefinition qTypeDefinition, RuntimeTypeHandle runtimeTypeHandle, IntPtr nonGcStaticFields, IntPtr gcStaticFields) { TypeLoaderLogger.WriteLine("Register new type with eetype = " + runtimeTypeHandle.ToIntPtr().LowLevelToString() + " nonGcStaticFields " + nonGcStaticFields.LowLevelToString() + " gcStaticFields " + gcStaticFields.LowLevelToString()); NamedTypeLookupResult result = _metadataToRuntimeTypeHandleHashtable.GetOrCreateValue(qTypeDefinition); result.VersionNumber = _namedTypeLookupLiveVersion + 1; result.RuntimeTypeHandle = runtimeTypeHandle; result.GcStaticFields = gcStaticFields; result.NonGcStaticFields = nonGcStaticFields; unsafe { result.RuntimeTypeHandleHashcode = (int)runtimeTypeHandle.ToEETypePtr()->HashCode; } NamedTypeLookupResult rthToMetadataResult = _runtimeTypeHandleToMetadataHashtable.AddOrGetExisting(result); if (!Object.ReferenceEquals(rthToMetadataResult, result)) { rthToMetadataResult.QualifiedTypeDefinition = qTypeDefinition; rthToMetadataResult.GcStaticFields = gcStaticFields; rthToMetadataResult.NonGcStaticFields = nonGcStaticFields; } }
internal TypeDesc GetTypeDescFromQHandle(QTypeDefinition qTypeDefinition) { #if ECMA_METADATA_SUPPORT if (qTypeDefinition.IsNativeFormatMetadataBased) #endif { MetadataReader nativeFormatMetadataReader = qTypeDefinition.NativeFormatReader; TypeDefinitionHandle typeDefinitionHandle = qTypeDefinition.NativeFormatHandle; NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoForMetadataReader(nativeFormatMetadataReader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(module); NativeFormatType nativeFormatType = (NativeFormatType)metadataUnit.GetType(typeDefinitionHandle); return(nativeFormatType); } #if ECMA_METADATA_SUPPORT else if (qTypeDefinition.IsEcmaFormatMetadataBased) { EcmaModuleInfo module = ModuleList.Instance.GetModuleInfoForMetadataReader(qTypeDefinition.EcmaFormatReader); Ecma.EcmaModule ecmaModule = ResolveEcmaModule(module); Ecma.EcmaType ecmaType = (Ecma.EcmaType)ecmaModule.GetType(qTypeDefinition.EcmaFormatHandle); return(ecmaType); } #endif return(null); }
static partial void TryGetFullNameFromTypeDefEcma(QTypeDefinition qTypeDefinition, List <int> genericParameterOffsets, ref string result);
public abstract bool TryGetNamedTypeForMetadata(QTypeDefinition qTypeDefinition, out RuntimeTypeHandle runtimeTypeHandle);
//============================================================================================== // Reflection Mapping Tables //============================================================================================== public abstract bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out QTypeDefinition qTypeDefinition);
static partial void TryGetFullNameFromTypeDefEcma(QTypeDefinition qTypeDefinition, ref string result);
/// <summary> /// Return the metadata handle for a TypeDef if the pay-for-policy enabled this type as browsable. This is used to obtain name and other information for types /// obtained via typeof() or Object.GetType(). This can include generic types (Foo<>) (not to be confused with generic instances of Foo<>). /// /// Preconditions: /// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.) /// </summary> /// <param name="runtimeTypeHandle">Runtime handle of the type in question</param> /// <param name="metadataReader">Metadata reader located for the type</param> /// <param name="typeDefHandle">TypeDef handle for the type</param> public unsafe bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out QTypeDefinition qTypeDefinition) { NamedTypeLookupResult result = _runtimeTypeHandleToMetadataHashtable.GetOrCreateValue(runtimeTypeHandle); qTypeDefinition = result.QualifiedTypeDefinition; return(qTypeDefinition.Reader != null); }