Ejemplo n.º 1
0
        private static Dictionary <int, SueData> LoadData(string path)
        {
            var sues = new Dictionary <int, SueData>();

            // Open the file to read from.
            using (StreamReader sr = File.OpenText(path))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    var nameSplit = s.Split(':');
                    var sueNumber = int.Parse(nameSplit[0].Split(' ')[1]);

                    var list      = s.Substring(nameSplit[0].Length + 2);
                    var listSplit = list.Split(',');

                    var newSue = new SueData();

                    foreach (var item in listSplit)
                    {
                        string itemName  = item.Split(':')[0].Trim(' ');
                        int    itemValue = int.Parse(item.Split(':')[1]);

                        Type         type = newSue.GetType();
                        PropertyInfo prop = type.GetProperty(itemName);
                        prop.SetValue(newSue, itemValue, null);
                    }

                    sues[sueNumber] = newSue;
                }
            }

            return(sues);
        }