Пример #1
0
 // load settings from specified location using default name
 public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType)
 {
     return(Load(defaultSettings, locationType, defaultSettings.DefaultName()));
 }
Пример #2
0
 // load settings from default file
 public static SettingsBase Load(SettingsBase defaultSettings)
 {
     return(Load(defaultSettings, LocationType.Application));
 }
Пример #3
0
        // 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));
        }
Пример #4
0
        // 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));
        }
Пример #5
0
		// load settings from default file
		public static SettingsBase Load(SettingsBase defaultSettings) 
		{
			return Load(defaultSettings, LocationType.User);
		}
Пример #6
0
		// load settings from specified location using default name
		public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType)
		{
			return Load(defaultSettings, locationType, defaultSettings.DefaultName());
		}
Пример #7
0
		// 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);
		}
Пример #8
0
		// 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);
		}
Пример #9
0
		// 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;
		}