public void RegisterNewNamedTypeRuntimeTypeHandle(MetadataReader metadataReader, TypeDefinitionHandle typeDefHandle, RuntimeTypeHandle runtimeTypeHandle, IntPtr nonGcStaticFields, IntPtr gcStaticFields) { NamedTypeMetadataDescription description = new NamedTypeMetadataDescription() { MetadataReader = metadataReader, TypeDefinition = typeDefHandle }; TypeLoaderLogger.WriteLine("Register new type with eetype = " + runtimeTypeHandle.ToIntPtr().LowLevelToString() + " nonGcStaticFields " + nonGcStaticFields.LowLevelToString() + " gcStaticFields " + gcStaticFields.LowLevelToString()); NamedTypeLookupResult result = _metadataToRuntimeTypeHandleHashtable.GetOrCreateValue(description); 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.TypeDefinition = typeDefHandle; rthToMetadataResult.MetadataReader = metadataReader; rthToMetadataResult.GcStaticFields = gcStaticFields; rthToMetadataResult.NonGcStaticFields = nonGcStaticFields; } }
/// <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); }
/// <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 MetadataReader metadataReader, out TypeDefinitionHandle typeDefHandle) { NamedTypeLookupResult result = _runtimeTypeHandleToMetadataHashtable.GetOrCreateValue(runtimeTypeHandle); metadataReader = result.MetadataReader; typeDefHandle = result.TypeDefinition; return(metadataReader != null); }
/// <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()); }
/// <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(MetadataReader metadataReader, TypeDefinitionHandle typeDefHandle, out RuntimeTypeHandle runtimeTypeHandle) { NamedTypeMetadataDescription description = new NamedTypeMetadataDescription() { MetadataReader = metadataReader, TypeDefinition = typeDefHandle }; runtimeTypeHandle = default(RuntimeTypeHandle); NamedTypeLookupResult result = _metadataToRuntimeTypeHandleHashtable.GetOrCreateValue(description); if (result.VersionNumber <= _namedTypeLookupLiveVersion) { runtimeTypeHandle = result.RuntimeTypeHandle; } return(!runtimeTypeHandle.IsNull()); }
public void RegisterNewNamedTypeRuntimeTypeHandle(QTypeDefinition qTypeDefinition, RuntimeTypeHandle runtimeTypeHandle, IntPtr nonGcStaticFields, IntPtr gcStaticFields) { TypeLoaderLogger.WriteLine("Register new type with MethodTable = " + 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; } }