static void Main(string[] args) { string JSONFilePath = GetJSONFilePathFromConsole(); try { JSONFileStructure jsonFileStructure = JSONParser.ParseJSONFile(JSONFilePath); try { List <ClassDescription> dtoClassDescriptions = JSONFileStructureAdapter.AdaptToClassDecriptionList(jsonFileStructure); string directoryPath = GetOutputDirectoryFromConsole(); List <DTODescription> dtoDecriptions = (new DTOGenerator(SettingsManager.GetThreadPoolLimit(), SettingsManager.GetDtoNamespace())).GenerateCode(dtoClassDescriptions); foreach (DTODescription dtoDescription in dtoDecriptions) { DTOClassesWriter.WriteToFile(dtoDescription, directoryPath); } Console.WriteLine("Done!"); Console.ReadLine(); } catch (InvalidOperationException e) { Console.WriteLine(e.Message); Console.ReadLine(); } } catch (JsonReaderException) { Console.WriteLine("Error reading JSON file"); Console.ReadLine(); } }
public static JSONFileStructure ParseJSONFile(string JSONFilePath) { using (StreamReader sr = new StreamReader(JSONFilePath)) { string JSONContent = sr.ReadToEnd(); JSONFileStructure DTOClassesDesription = JsonConvert.DeserializeObject <JSONFileStructure>(JSONContent); return(DTOClassesDesription); } }