예제 #1
0
        public static void WriteConfigTo(string filePath, IniConfig config)
        {
            StringBuilder configSB = new StringBuilder();

            configSB.AppendLine(INI_HEAD_CONTENT);

            dynamic dynamicConfig = config.AsDynamic();
            Dictionary <string, IniGroup> groupDic = dynamicConfig.groupDic;

            if (groupDic != null && groupDic.Count > 0)
            {
                foreach (var kvp in groupDic)
                {
                    IniGroup group = kvp.Value;
                    configSB.AppendLine($"#{group.Name}|{group.Comment}");

                    dynamic dynamicGroup = group.AsDynamic();
                    Dictionary <string, IniData> dataDic = dynamicGroup.dataDic;
                    foreach (var kvp2 in dataDic)
                    {
                        IniData data = kvp2.Value;
                        configSB.AppendLine($"-{data.Key}|{data.Value}|{data.Comment}|{string.Join(",", data.OptionValues)}");
                    }
                }

                configSB.AppendLine();
            }

            File.WriteAllText(filePath, configSB.ToString());
        }