예제 #1
0
        public void AddFile <T>(string input, T data)
        {
            if (!System.IO.File.Exists(Path.Combine(GetFullPath(), input)))
            {
                switch (Parser)
                {
                case StorageSystem.FileType.XML:
                    var document = new System.Xml.Linq.XDocument();

                    using (var writer = document.CreateWriter())
                        new XmlSerializer(typeof(T)).Serialize(writer, data);

                    document.Save(Path.Combine(GetFullPath(), input + ".xml"));

                    break;

                case StorageSystem.FileType.JSON:
                    var jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented);

                    System.IO.File.WriteAllText(Path.Combine(GetFullPath(), input + ".json"), jsonData);

                    break;
                }
            }
        }