/// <summary> /// Load the settings object from the specified file. /// </summary> /// <param name="file">The file to load the managed settings object from.</param> /// <exception cref="ArgumentException"> /// <paramref name="file" /> is a zero-length string, contains only white space, or /// contains one or more invalid characters as defined by <see cref="System.IO.Path.InvalidPathChars" />. /// </exception> /// <exception cref="NotSupportedException"><paramref name="file" /> is in an invalid path format. </exception> /// <exception cref="ArgumentNullException"><paramref name="file" /> is <c>null</c>. </exception> /// <exception cref="PathTooLongException"> /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than /// 260 characters. /// </exception> /// <exception cref="FileNotFoundException">The file specified in <paramref name="file" /> was not found. </exception> /// <exception cref="DirectoryNotFoundException">The specified path is invalid, (for example, it is on an unmapped drive). </exception> /// <exception cref="UnauthorizedAccessException"> /// <paramref name="file" /> specified a directory.-or- The caller does not /// have the required permission. /// </exception> /// <exception cref="InvalidOperationException">An error occurred during deserialization. The original exception is available using the <see cref="P:System.Exception.InnerException" /> property. </exception> public void Load(string file) { var serializer = new XmlSerializer(typeof(T)); var settings = new XmlReaderSettings() { IgnoreWhitespace = false, CloseInput = true }; using (var reader = XmlReader.Create(File.OpenRead(file), settings)) { Settings = (T)serializer.Deserialize(reader); } DefaultValueInitializer.Init(Settings); }
/// <summary> /// Load the settings object from the specified file. /// </summary> /// <param name="input">The stream to read the managed settings object from.</param> /// <param name="closeInput">whether or not this function should close <paramref name="input"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="input" /> is null. </exception> /// <exception cref="InvalidOperationException">An error occurred during deserialization. The original exception is available using the <see cref="P:System.Exception.InnerException" /> property. </exception> public void Load(Stream input, bool closeInput = false) { var serializer = new XmlSerializer(typeof(T)); var settings = new XmlReaderSettings() { IgnoreWhitespace = false, CloseInput = closeInput }; using (var reader = XmlReader.Create(input, settings)) { Settings = (T)serializer.Deserialize(reader); } DefaultValueInitializer.Init(Settings); }
/// <summary> /// Reset all settings properties to default in the settings managed settings object. /// </summary> public void ApplyDefaults() { Settings = new T(); DefaultValueInitializer.Init(Settings); }