Exemple #1
0
        private void Load(string path, string property)
        {
            var pi  = typeof(Statistics).GetProperty(property);
            var doc = new CsvDocument();

            doc.Load(path);
            foreach (var item in doc.Items)
            {
                var countryName = item[0];
                if (!Countries.ContainsKey(countryName))
                {
                    Countries[countryName] = new Country(countryName);
                }
                var country = Countries[countryName];
                for (int i = 1; i < doc.Headers.Length; i++)
                {
                    int year = int.Parse(doc.Headers[i]);
                    if (!country.StatisticsByYear.ContainsKey(year))
                    {
                        country.StatisticsByYear[year] = new Statistics(year);
                    }
                    double value;
                    if (double.TryParse(item[i], out value))
                    {
                        var statistics = country.StatisticsByYear[year];
                        pi.SetValue(statistics, value, null);
                    }
                }
            }
        }
Exemple #2
0
 private void Load(string path, string property)
 {
     var pi = typeof(Statistics).GetProperty(property);
     var doc = new CsvDocument();
     doc.Load(path);
     foreach (var item in doc.Items)
     {
         var countryName = item[0];
         if (!Countries.ContainsKey(countryName))
             Countries[countryName] = new Country(countryName);
         var country = Countries[countryName];
         for (int i = 1; i < doc.Headers.Length; i++)
         {
             int year = int.Parse(doc.Headers[i]);
             if (!country.StatisticsByYear.ContainsKey(year))
                 country.StatisticsByYear[year] = new Statistics(year);
             double value;
             if (double.TryParse(item[i], out value))
             {
                 var statistics = country.StatisticsByYear[year];
                 pi.SetValue(statistics, value, null);
             }
         }
     }
 }