Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                PrintHelp();
                return;
            }

            var consoleOptions = new ConsoleOptions(args);

            var generatorOptions = new Options
            {
                NameSpace         = consoleOptions.NameSpace,
                DeclareDataMember = consoleOptions.DeclareDataMember,
                ListType          = consoleOptions.ListType
            };
            var generator = new JsonToCsharpGenerator(generatorOptions);

            var task = Task.Run(() =>
            {
                try
                {
                    using (var reader = new FileReader(consoleOptions.InPath.FullName))
                    {
                        var classResults = generator.Create(consoleOptions.ClassName, reader);

                        foreach (var(className, generatedText) in classResults)
                        {
                            var outputPath = Path.Combine(consoleOptions.OutDir.FullName, $"{className}.cs");
                            File.WriteAllText(outputPath, generatedText);
                        }
                    }
                }
                catch (Exception e)
                {
                    Write($"error:\n{e}");
                }
            });

            char[] rotation = { '/', '-', '\\', '|', '/', '-', '\\', '|' };
            int    i        = 0;

            while (task.IsCompleted == false)
            {
                SetCursorPosition(0, 0);
                Write($"[{rotation[i]}] Executing");
                i = (i + 1) % rotation.Length;
            }
            WriteLine();
            WriteLine("Complete!");
        }
Ejemplo n.º 2
0
        public ActionResult <Result <IReadOnlyDictionary <string, string> > > Generate([FromBody] JsonSendModel input)
        {
            using (var reader = new MemoryReader(input.JsonText))
            {
                var options = new Options
                {
                    DeclareDataMember = false,
                    ListType          = Enum.Parse <ListType>(input.ListType),
                    NameSpace         = null
                };

                try
                {
                    var classData = new JsonToCsharpGenerator(options).Create(input.BaseClassName, reader);

                    return(Result <IReadOnlyDictionary <string, string> > .CreateSuccess(classData));
                }
                catch (Exception e)
                {
                    return(Result <IReadOnlyDictionary <string, string> > .CreateFail(e.Message));
                }
            }
        }