using System; using System.Configuration; using System.Linq; using System.Reflection; namespace Developpez.Dotnet.Windows.Configuration { /// /// Permet de récupérer les settings de l'application /// public class SettingsManager { static SettingsManager() { _settings = GetSettings(); } private static ApplicationSettingsBase GetSettings() { Assembly asm = AssemblyManager.GetEntryAssembly(); if (asm != null) { Type settingsType = (from t in asm.GetTypes() where t.IsSubclassOf(typeof(ApplicationSettingsBase)) select t).FirstOrDefault(); if (settingsType != null) { PropertyInfo pi = settingsType.GetProperty("Default", BindingFlags.Public | BindingFlags.Static); if (pi != null) { return pi.GetValue(null, null) as ApplicationSettingsBase; } else { return Activator.CreateInstance(settingsType) as ApplicationSettingsBase; } } } return null; } private static ApplicationSettingsBase _settings; /// /// Renvoie ou définit les settings de l'application /// public static ApplicationSettingsBase Settings { get { return _settings; } set { _settings = value; } } } }