protected override IEntityHandleObject CreateValueFromKey(EntityHandle handle) { object item; switch (handle.Kind) { case HandleKind.TypeDefinition: item = new EcmaType(_module, (TypeDefinitionHandle)handle); break; case HandleKind.MethodDefinition: { MethodDefinitionHandle methodDefinitionHandle = (MethodDefinitionHandle)handle; TypeDefinitionHandle typeDefinitionHandle = _module._metadataReader.GetMethodDefinition(methodDefinitionHandle).GetDeclaringType(); EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle); item = new EcmaMethod(type, methodDefinitionHandle); } break; case HandleKind.FieldDefinition: { FieldDefinitionHandle fieldDefinitionHandle = (FieldDefinitionHandle)handle; TypeDefinitionHandle typeDefinitionHandle = _module._metadataReader.GetFieldDefinition(fieldDefinitionHandle).GetDeclaringType(); EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle); item = new EcmaField(type, fieldDefinitionHandle); } break; case HandleKind.TypeReference: item = _module.ResolveTypeReference((TypeReferenceHandle)handle); break; case HandleKind.MemberReference: item = _module.ResolveMemberReference((MemberReferenceHandle)handle); break; case HandleKind.AssemblyReference: item = _module.ResolveAssemblyReference((AssemblyReferenceHandle)handle); break; case HandleKind.TypeSpecification: item = _module.ResolveTypeSpecification((TypeSpecificationHandle)handle); break; case HandleKind.MethodSpecification: item = _module.ResolveMethodSpecification((MethodSpecificationHandle)handle); break; case HandleKind.ExportedType: item = _module.ResolveExportedType((ExportedTypeHandle)handle); break; case HandleKind.StandaloneSignature: item = _module.ResolveStandaloneSignature((StandaloneSignatureHandle)handle); break; case HandleKind.ModuleDefinition: // ECMA-335 Partition 2 II.22.38 1d: This should not occur in a CLI ("compressed metadata") module, // but resolves to "current module". item = _module; break; default: throw new BadImageFormatException("Unknown metadata token type: " + handle.Kind); } switch (handle.Kind) { case HandleKind.TypeDefinition: case HandleKind.MethodDefinition: case HandleKind.FieldDefinition: // type/method/field definitions directly correspond to their target item. return((IEntityHandleObject)item); default: // Everything else is some form of reference which cannot be self-describing return(new EcmaObjectLookupWrapper(handle, item)); } }
protected override IEntityHandleObject CreateValueFromKey(EntityHandle handle) { object item; switch (handle.Kind) { case HandleKind.TypeDefinition: item = new EcmaType(_module, (TypeDefinitionHandle)handle); break; case HandleKind.MethodDefinition: { MethodDefinitionHandle methodDefinitionHandle = (MethodDefinitionHandle)handle; TypeDefinitionHandle typeDefinitionHandle = _module._metadataReader.GetMethodDefinition(methodDefinitionHandle).GetDeclaringType(); EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle); item = new EcmaMethod(type, methodDefinitionHandle); } break; case HandleKind.FieldDefinition: { FieldDefinitionHandle fieldDefinitionHandle = (FieldDefinitionHandle)handle; TypeDefinitionHandle typeDefinitionHandle = _module._metadataReader.GetFieldDefinition(fieldDefinitionHandle).GetDeclaringType(); EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle); item = new EcmaField(type, fieldDefinitionHandle); } break; case HandleKind.TypeReference: item = _module.ResolveTypeReference((TypeReferenceHandle)handle); break; case HandleKind.MemberReference: item = _module.ResolveMemberReference((MemberReferenceHandle)handle); break; case HandleKind.AssemblyReference: item = _module.ResolveAssemblyReference((AssemblyReferenceHandle)handle); break; case HandleKind.TypeSpecification: item = _module.ResolveTypeSpecification((TypeSpecificationHandle)handle); break; case HandleKind.MethodSpecification: item = _module.ResolveMethodSpecification((MethodSpecificationHandle)handle); break; case HandleKind.ExportedType: item = _module.ResolveExportedType((ExportedTypeHandle)handle); break; // TODO: Resolve other tokens default: throw new BadImageFormatException("Unknown metadata token type"); } switch (handle.Kind) { case HandleKind.TypeDefinition: case HandleKind.MethodDefinition: case HandleKind.FieldDefinition: // type/method/field definitions directly correspond to their target item. return((IEntityHandleObject)item); default: // Everything else is some form of reference which cannot be self-describing return(new EcmaObjectLookupWrapper(handle, item)); } }