// load settings from specified location using default name public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType) { return(Load(defaultSettings, locationType, defaultSettings.DefaultName())); }
// load settings from default file public static SettingsBase Load(SettingsBase defaultSettings) { return(Load(defaultSettings, LocationType.Application)); }
// Load settings from specified location using specified path and default filename public static SettingsBase LoadFromPath(SettingsBase defaultSettings, string path) { string fileName = Path.Combine(path, defaultSettings.DefaultName()); return(Load(defaultSettings, fileName)); }
// Load settings from specified location using specified name public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType, string name) { string fileName = Path.Combine(DefaultLocation(locationType), name); return(Load(defaultSettings, fileName)); }
// load settings from default file public static SettingsBase Load(SettingsBase defaultSettings) { return Load(defaultSettings, LocationType.User); }
// load settings from specified location using default name public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType) { return Load(defaultSettings, locationType, defaultSettings.DefaultName()); }
// Load settings from specified location using specified name public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType, string name) { string fileName = Path.Combine(DefaultLocation(locationType), name); return Load(defaultSettings, fileName); }
// Load settings from specified location using specified path and default filename public static SettingsBase LoadFromPath(SettingsBase defaultSettings, string path) { string fileName = Path.Combine(path, defaultSettings.DefaultName()); return Load(defaultSettings, fileName); }
// load settings from a given file (full path and name) public static SettingsBase Load(SettingsBase defaultSettings, string fileName) { // remember where we loaded from for a later save defaultSettings.m_fileName = fileName; // return the default instance if the file does not exist if(!File.Exists(fileName)) { return defaultSettings; } // start out with the default instance SettingsBase settings = defaultSettings; try { XmlSerializer ser = new XmlSerializer(defaultSettings.GetType()); using(TextReader tr = new StreamReader(fileName)) { settings = (SettingsBase)ser.Deserialize(tr); settings.m_fileName = fileName; // remember where we loaded from for a later save } } catch(Exception ex) { throw new System.Exception(String.Format("Loading settings from file '{1}' to {0} failed", defaultSettings.GetType().ToString(), fileName), ex); } return settings; }