Exemplo n.º 1
0
        public static bool Set <T> (string setting, T newValue)
        {
            ConfigrationModel config = GetConfig();

            try
            {
                typeof(ConfigrationModel).GetProperty(setting).SetValue(config, newValue);
            }
            catch (NullReferenceException)
            {
                return(false);
            }


            if (File.Exists(PathManager.ConfigurationPath))
            {
                File.Delete(PathManager.ConfigurationPath);
            }

            using (StreamWriter writer = File.CreateText(PathManager.ConfigurationPath))
            {
                JsonSerializer serial = new JsonSerializer();
                serial.Formatting = Formatting.Indented;
                serial.Serialize(writer, config);
            }

            return(true);
        }
Exemplo n.º 2
0
 public static string Get(string setting)
 {
     try
     {
         ConfigrationModel config = GetConfig();
         object            value  = typeof(ConfigrationModel).GetProperty(setting).GetValue(config);
         return(value.ToString());
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        public static Dictionary <string, string> GetAllConfiguration()
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            PropertyInfo[]    _props = typeof(ConfigrationModel).GetProperties();
            ConfigrationModel config = GetConfig();

            foreach (PropertyInfo prop in _props)
            {
                var x = typeof(ConfigrationModel).GetProperty(prop.Name).GetValue(config);
                dict.Add(prop.Name, x.ToString());
            }

            return(dict);
        }