コード例 #1
0
 private static void SetPropertyValue(string name, string value, SimpleMinerSettings setting)
 {
     foreach (PropertyInfo property in setting.GetType().GetProperties())
     {
         try
         {
             if (property.Name == name)
             {
                 if (property.PropertyType == typeof(bool))
                 {
                     if (value == "False")
                     {
                         property.SetValue(setting, false, null);
                         break;
                     }
                     property.SetValue(setting, true, null);
                     break;
                 }
                 else if (property.PropertyType == typeof(string))
                 {
                     property.SetValue(setting, value, null);
                     break;
                 }
                 else if (property.PropertyType == typeof(int))
                 {
                     property.SetValue(setting, Convert.ToInt32(value), null);
                     break;
                 }
                 else if (property.PropertyType == typeof(byte))
                 {
                     property.SetValue(setting, Convert.ToByte(value), null);
                     break;
                 }
                 else if (property.PropertyType == typeof(double))
                 {
                     property.SetValue(setting, Convert.ToDouble(value), null);
                     break;
                 }
                 property.SetValue(setting, Convert.ToInt32(value), null);
                 break;
             }
         }
         catch
         {
         }
     }
 }
コード例 #2
0
        public static void WriteParameters(SimpleMinerSettings setting)
        {
            if (setting == null || setting.ApplicationMode.Equals(Consts.ApplicationMode.Silent))
            {
                return;
            }

            using (StreamWriter text = File.CreateText(Consts.ApplicationConfigFile))
            {
                foreach (PropertyInfo property in setting.GetType().GetProperties())
                {
                    text.WriteLine(property.Name + "=" + property.GetValue(setting, null));
                }
            }
            //megvárjuk, hogy kiíródjon a fájl
            System.Threading.Thread.Sleep(300);
        }