コード例 #1
0
        internal static void SaveSettings(MemopadSettings settings)
        {
            var serializer = new DataContractSerializer(typeof(MemopadSettings));

            using (var stream = new FileStream(MemopadConsts.SettingsFilePath, FileMode.Create, FileAccess.Write))
                using (var writer = XmlWriter.Create(stream)) {
                    serializer.WriteObject(writer, settings);
                }
        }
コード例 #2
0
        // ========================================
        // static method
        // ========================================
        internal static MemopadSettings LoadSettings()
        {
            var ret = default(MemopadSettings);

            try {
                if (File.Exists(MemopadConsts.SettingsFilePath))
                {
                    var serializer = new DataContractSerializer(typeof(MemopadSettings));
                    using (var stream = new FileStream(MemopadConsts.SettingsFilePath, FileMode.Open, FileAccess.Read))
                        using (var reader = XmlReader.Create(stream)) {
                            ret = serializer.ReadObject(reader) as MemopadSettings;
                        }
                }
            } catch (Exception e) {
                Logger.Warn("Settings load failed", e);
            }

            if (ret == null)
            {
                ret = new MemopadSettings();
            }

            return(ret);
        }