예제 #1
0
        // IO
        public static void Load()
        {
            var path = SavePath;

            var settings = new IniSettings();

            settings.Load(path);

            foreach (var prop in Properties.Values)
            {
                if (prop.PropertyType == typeof(string))
                {
                    prop.SetValue(null, settings.GetString(prop.Name, (string)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(int))
                {
                    prop.SetValue(null, settings.GetInt(prop.Name, (int)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(double))
                {
                    prop.SetValue(null, settings.GetDouble(prop.Name, (double)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(bool))
                {
                    prop.SetValue(null, settings.GetBool(prop.Name, (bool)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(string[]))
                {
                    string[] vals;
                    if (settings.TryGetStrings(prop.Name, out vals))
                    {
                        prop.SetValue(null, vals);
                    }
                }
                else if (prop.PropertyType == typeof(ConcurrentDictionary <string, object>))
                {
                    var dict = (ConcurrentDictionary <string, object>)prop.GetValue(null);

                    dict.Clear();

                    string[] vals;
                    if (settings.TryGetStrings(prop.Name, out vals))
                    {
                        foreach (var s in vals)
                        {
                            dict[s] = null;
                        }
                    }
                }
                else if (prop.PropertyType == typeof(List <int>))
                {
                    int xd;
                    prop.SetValue(null, settings.GetString(prop.Name, "").Split(',').Select(x => x.Trim())
                                  .Where(x => int.TryParse(x, out xd)).Select(x => int.Parse(x)).ToList());
                }
            }
        }
예제 #2
0
        // IO
        public static void Load()
        {
            var path = SavePath;

            var settings = new IniSettings();

            settings.Load(path);
            var parser = new JsonParser();


            foreach (var prop in Properties.Values)
            {
                if (prop.PropertyType == typeof(string))
                {
                    prop.SetValue(null, settings.GetString(prop.Name, (string)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(int))
                {
                    prop.SetValue(null, settings.GetInt(prop.Name, (int)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(double))
                {
                    prop.SetValue(null, settings.GetDouble(prop.Name, (double)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(bool))
                {
                    prop.SetValue(null, settings.GetBool(prop.Name, (bool)prop.GetValue(null)));
                }
                else if (prop.PropertyType == typeof(string[]))
                {
                    string[] vals;
                    if (settings.TryGetStrings(prop.Name, out vals))
                    {
                        prop.SetValue(null, vals);
                    }
                }
                else if (prop.PropertyType == typeof(ConcurrentDictionary <string, object>))
                {
                    var dict = (ConcurrentDictionary <string, object>)prop.GetValue(null);

                    dict.Clear();

                    string[] vals;
                    if (settings.TryGetStrings(prop.Name, out vals))
                    {
                        foreach (var s in vals)
                        {
                            dict[s] = null;
                        }
                    }
                }
                else if (prop.PropertyType == typeof(ConcurrentDictionary <string, string>))
                {
                    var dict = (ConcurrentDictionary <string, string>)prop.GetValue(null);

                    dict.Clear();

                    string val;
                    val = settings.GetString(prop.Name, "");
                    if (!String.IsNullOrEmpty(val))
                    {
                        try {
                            var newdict = JsonConvert.DeserializeObject <ConcurrentDictionary <string, string> >(val);
                            if (newdict != null)
                            {
                                prop.SetValue(null, newdict);
                            }
                        } catch {}
                    }
                }
                else if (prop.PropertyType == typeof(List <int>))
                {
                    int xd;
                    prop.SetValue(null, settings.GetString(prop.Name, "").Split(',').Select(x => x.Trim())
                                  .Where(x => int.TryParse(x, out xd)).Select(x => int.Parse(x)).ToList());
                }
            }
        }