IExtractedEntity Create(GenericContext gc, MemberReferenceHandle handle) { var mr = mdReader.GetMemberReference(handle); switch (mr.GetKind()) { case MemberReferenceKind.Method: return(new MemberReferenceMethod(gc, handle)); case MemberReferenceKind.Field: return(new MemberReferenceField(gc, handle)); default: throw new InternalError("Unhandled member reference handle"); } }
IExtractedEntity CreateGenericHandle(GenericContext gc, Handle handle) { IExtractedEntity entity; switch (handle.Kind) { case HandleKind.MethodDefinition: entity = new DefinitionMethod(gc, (MethodDefinitionHandle)handle); break; case HandleKind.MemberReference: entity = Create(gc, (MemberReferenceHandle)handle); break; case HandleKind.MethodSpecification: entity = new MethodSpecificationMethod(gc, (MethodSpecificationHandle)handle); break; case HandleKind.FieldDefinition: entity = new DefinitionField(gc, (FieldDefinitionHandle)handle); break; case HandleKind.TypeReference: var tr = new TypeReferenceType(this, (TypeReferenceHandle)handle); if (tr.TryGetPrimitiveType(out var pt)) { // Map special names like `System.Int32` to `int` return(pt); } entity = tr; break; case HandleKind.TypeSpecification: return(Entities.Type.DecodeType(gc, (TypeSpecificationHandle)handle)); case HandleKind.TypeDefinition: entity = new TypeDefinitionType(this, (TypeDefinitionHandle)handle); break; default: throw new InternalError("Unhandled handle kind " + handle.Kind); } Populate(entity); return(entity); }
/// <summary> /// Creates an entity from a Handle in a GenericContext. /// The type of the returned entity depends on the type of the handle. /// The GenericContext is needed because some handles are generics which /// need to be expanded in terms of the current instantiation. If this sounds /// complex, you are right. /// /// The pair (h,genericContext) is cached in case it is needed again. /// </summary> /// <param name="h">The handle of the entity.</param> /// <param name="genericContext">The generic context.</param> /// <returns></returns> public IExtractedEntity CreateGeneric(GenericContext genericContext, Handle h) => genericHandleFactory[genericContext, h];