Exemplo n.º 1
0
        public static void GenerateTo(JsonSchemaSource root, DirectoryInfo dir, bool clearFolder)
        {
            // clear or create folder
            if (dir.Exists)
            {
                if (dir.EnumerateFileSystemInfos().Any())
                {
                    if (!clearFolder)
                    {
                        Console.WriteLine($"{dir} is not empty.");
                        return;
                    }

                    // clear
                    ClearFolder(dir);
                }
            }
            else
            {
                Console.WriteLine($"create: {dir}");
                dir.Create();
            }

            foreach (var s in root.Traverse())
            {
                // title を掃除
                s.title = CleanupTitle(s.title);
            }

            {
                var dst = Path.Combine(dir.FullName, "Format.g.cs");
                Console.WriteLine(dst);
                using (var w = new StringWriter())
                {
                    FormatWriter.Write(w, root, GetStem(root.FilePath.Name));
                    File.WriteAllText(dst, w.ToString().Replace("\r\n", "\n"));
                }
            }
            {
                var dst = Path.Combine(dir.FullName, "Deserializer.g.cs");
                Console.WriteLine(dst);
                using (var w = new StringWriter())
                {
                    DeserializerWriter.Write(w, root, GetStem(root.FilePath.Name));
                    File.WriteAllText(dst, w.ToString().Replace("\r\n", "\n"));
                }
            }
            {
                var dst = Path.Combine(dir.FullName, "Serializer.g.cs");
                Console.WriteLine(dst);
                using (var w = new StringWriter())
                {
                    SerializerWriter.Write(w, root, GetStem(root.FilePath.Name));
                    File.WriteAllText(dst, w.ToString().Replace("\r\n", "\n"));
                }
            }
        }
Exemplo n.º 2
0
        public static void GenerateTo(JsonSchemaSource root, DirectoryInfo formatDir, DirectoryInfo serializerDir)
        {
            CleanDirectory(formatDir);
            CleanDirectory(serializerDir);

            foreach (var s in root.Traverse())
            {
                // title を掃除
                s.title = CleanupTitle(s.title);
            }

            {
                var dst = Path.Combine(formatDir.FullName, "Format.g.cs");
                Console.WriteLine(dst);
                using (var w = new StringWriter())
                {
                    FormatWriter.Write(w, root, GetStem(root.FilePath.Name));
                    WriteAllTextForce(dst, w.ToString().Replace("\r\n", "\n"));
                }
            }
            {
                var dst = Path.Combine(serializerDir.FullName, "Deserializer.g.cs");
                Console.WriteLine(dst);
                using (var w = new StringWriter())
                {
                    DeserializerWriter.Write(w, root, GetStem(root.FilePath.Name));
                    WriteAllTextForce(dst, w.ToString().Replace("\r\n", "\n"));
                }
            }
            {
                var dst = Path.Combine(serializerDir.FullName, "Serializer.g.cs");
                Console.WriteLine(dst);
                using (var w = new StringWriter())
                {
                    SerializerWriter.Write(w, root, GetStem(root.FilePath.Name));
                    WriteAllTextForce(dst, w.ToString().Replace("\r\n", "\n"));
                }
            }
        }