Пример #1
0
        public static async Task <T> Load <T>(this StorageFile file)
        {
            var s = XmlSerializerUtil.GetSerializer(typeof(T));

            using (var st = await file.OpenStreamForReadAsync())
            {
                try
                {
                    return((T)s.Deserialize(st));
                }
                catch (Exception)
                {
                    return(default(T));
                }
            }
        }
Пример #2
0
        public static async Task Save <T>(this StorageFile file, T obj)
        {
            var s       = XmlSerializerUtil.GetSerializer(typeof(T));
            var setting = new XmlWriterSettings
            {
                NewLineOnAttributes = true,
                Indent = true,
            };
            var ns = new XmlSerializerNamespaces();

            ns.Add(string.Empty, string.Empty);

            using (var st = await file.OpenStreamForWriteAsync())
                using (var xmlWriter = XmlWriter.Create(st, setting))
                {
                    s.Serialize(xmlWriter, obj);
                }
        }