public FileParser GetFileParserInstance(string filePath) { var fileExtn = Path.GetExtension(filePath); FileParser fileParser = null; switch (fileExtn) { case ".xml": fileParser = new XmlFileParser(); break; case ".json": fileParser = new JsonFileParser(); break; } return(fileParser); }
static void Main(string[] args) { // TODO: Create some logic that loops through all files in the FeedData and loads them automatically, rather // than picking out files specifically // TODO: Potentially use a factory to provide the correct parser based on extension. Could then just use // the parser interface instead of concerete classes here. var xmlParser = new XmlFileParser(); var jsonParser = new JsonFileParser(); var content = RaceFileReader.ReadFile("FeedData/Caulfield_Race1.xml"); var xmlRace = xmlParser.ProcessFileContent(content); var jsonContent = RaceFileReader.ReadFile("FeedData/Wolferhampton_Race1.json"); var jsonRace = jsonParser.ProcessFileContent(jsonContent); RaceOutputter.OutputByHorsePrice(xmlRace); RaceOutputter.OutputByHorsePrice(jsonRace); }