public override IEnumerable<MethodDesc> GetMethods() { foreach (var handle in _typeDefinition.GetMethods()) { yield return (EcmaMethod)_module.GetObject(handle); } }
private TypeDesc ResolveHandle(EntityHandle handle) { object resolvedValue; if (_ecmaModule != null) { resolvedValue = _ecmaModule.GetObject(handle, _notFoundBehavior); } else { resolvedValue = _typeResolver(handle, _notFoundBehavior); } if (resolvedValue == null) { return(null); } if (resolvedValue is ResolutionFailure failure) { SetResolutionFailure(failure); return(null); } if (resolvedValue is TypeDesc type) { return(type); } else { throw new BadImageFormatException("Type expected"); } }
public bool GeneratesMetadata(EcmaModule module, ExportedTypeHandle exportedTypeHandle) { try { // Generate the forwarder only if we generated the target type. // If the target type is in a different compilation group, assume we generated it there. var targetType = (MetadataType)module.GetObject(exportedTypeHandle); return(GeneratesMetadata(targetType) || !_factory.CompilationModuleGroup.ContainsType(targetType)); } catch (TypeSystemException) { // No harm in generating a forwarder that didn't resolve. // We'll get matching behavior at runtime. return(true); } }
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)); } }