Yaml ์ด๋ž€?

YAML์€ ์‚ฌ๋žŒ์ด ์ฝ๊ณ  ์“ฐ๊ธฐ ์‰ฌ์šด ๋ฐ์ดํ„ฐ ์ง๋ ฌํ™” ์–‘์‹ ์ž…๋‹ˆ๋‹ค. ์ด์ œ ๋งŽ์€ ๋ถ„๋“ค์ด JSON์œผ๋กœ ์„ค์ •ํŒŒ์ผ์„ ๊ตฌ์„ฑํ•˜์‹ค ํ…๋ฐ์š” YAML์„ ๋‘˜๋Ÿฌ๋ณด์‹œ๊ณ  YAML๋กœ ๋ฐ”๊ฟ”๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started/

์ข‹์•„์š” 3

์•ผ๋ฉœ ์ €๋„ ํŒŒ์ดํ”„๋ผ์ธ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ง€๋งŒ ์ง๊ด€์ ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ใ…Žใ…Ž

์ข‹์•„์š” 1

@dimohy @Vincent

๋งˆ์นจ ์„ค์ •ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์•ผ ํ•ด์„œ ๋ฐฉ๊ธˆ ์ ์šฉํ•ด๋ดค๋Š”๋ฐ์š”.

์ €๋„ ์•ž์œผ๋กœ ์ ๊ทน์ ์œผ๋กœ ์จ๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค. :smile:


๊ทธ๋ฆฌ๊ณ  ์ œ๊ฐ€ ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ฌ์šฉํ•œ Serialize/Deserialize ๋ถ€๋ถ„๋„ ํ•„์š”ํ•˜์‹  ๋ถ„์„ ์œ„ํ•ด ์•„๋ž˜ ๋‚จ๊น๋‹ˆ๋‹ค.
Yaml Serialize/Deserialize C#

using DevFlow.Data;
using DevFlow.Data.Settings;
using System;
using System.IO;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace DevFlow.Windowbase.Flowbase
{
    public class FlowConfig
    {
        public static string WIN_PATH { get; }
        public static string SYS_PATH { get; }
        public static string CFG_PATH { get; }
        public static ConfigModel Config { get; private set; }

        static FlowConfig()
        {
            WIN_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            SYS_PATH = string.Format(@"{0}\DevFlow\System", WIN_PATH);
            CFG_PATH = string.Format(@"{0}\Config.yaml", SYS_PATH);

            LoadConfigFile();
        }

        private static void LoadConfigFile()
        {
            if (!Directory.Exists(SYS_PATH))
            {
                Directory.CreateDirectory(SYS_PATH);
            }

            if (!File.Exists(CFG_PATH))
            {
                SaveConfig(new ConfigModel());
            }

            var deserializer = new DeserializerBuilder()
              .WithNamingConvention(CamelCaseNamingConvention.Instance)
              .Build();

            Config = deserializer.Deserialize<ConfigModel>(File.ReadAllText(CFG_PATH));
        }

        public static void SaveLanguage(LanguageType lang)
        {
            Config.Language = lang;
            SaveConfig(Config);
        }

        public static void SaveTheme(ThemeType theme)
        {
            Config.Theme = theme;
            SaveConfig(Config);
        }

        public static ConfigModel LoadConfig()
        {
            return Config;
        }

        private static void SaveConfig(ConfigModel config)
        {
            var serializer = new SerializerBuilder()
                .WithNamingConvention(CamelCaseNamingConvention.Instance)
                .Build();

            var yaml = serializer.Serialize(config);

            File.WriteAllText(CFG_PATH, yaml);
        }
    }
}
์ข‹์•„์š” 2