/* Methods */ /// <summary> /// Creates an appropriate type for the specified entity. /// </summary> /// <param name="repository"> /// The <see cref="IEveRepository" /> which contains the entity adapter. /// </param> /// <param name="entity"> /// The data entity. /// </param> /// <returns> /// An <see cref="EveType" /> of the appropriate derived type, based on the /// contents of <paramref name="entity" />. /// </returns> public static EveType Create(IEveRepository repository, EveTypeEntity entity) { Contract.Requires(repository != null, "The repository associated with the object cannot be null."); Contract.Requires(entity != null, "The entity cannot be null."); Contract.Ensures(Contract.Result <EveType>() != null); // First, check for derived entity types. These are entities that // have additional fields in ancillary tables. // BlueprintTypeEntities always map to StationType BlueprintTypeEntity blueprintTypeEntity = entity as BlueprintTypeEntity; if (blueprintTypeEntity != null) { return(new BlueprintType(repository, blueprintTypeEntity)); } // StationTypeEntities always map to StationType StationTypeEntity stationTypeEntity = entity as StationTypeEntity; if (stationTypeEntity != null) { return(new StationType(repository, stationTypeEntity)); } // For the remainder, the actual entity is the same type, and we need to // determine the EVE type based on its property values. // Use the item's group and category to determine the correct derived type Group group = repository.GetGroupById(entity.GroupId); switch (group.CategoryId) { // All items under category Skill map to SkillType case CategoryId.Skill: return(new SkillType(repository, entity)); } // If we don't have a specific derived type for the provided entity, // fall back on a GenericType wrapper. return(new GenericType(repository, entity)); }