public void SaveToCSV(List <T> devs, string filepath)
        {
            List <string> rows  = new List <string>();
            T             entry = new T();
            var           cols  = entry.GetType().GetProperties();

            string row = "";

            foreach (var col in cols)
            {
                row += $",{col.Name}";
            }

            row = row.Substring(1);

            rows.Add(row);

            foreach (var dev in devs)
            {
                row = "";
                bool UnusableWords = false;
                foreach (var col in cols)
                {
                    string value = col.GetValue(dev, null).ToString();

                    UnusableWords = UnusableWordDetector(value);
                    if (UnusableWords)
                    {
                        BadEntryFound?.Invoke(this, dev);
                        break;
                    }

                    row += $",{value}";
                }

                if (UnusableWords)
                {
                    continue;
                }
                else
                {
                    row = row.Substring(1);

                    rows.Add(row);
                }
            }

            File.WriteAllLines(filepath, rows);
        }
Exemplo n.º 2
0
        public void SaveToCSV(List <T> items, string filePath)
        {
            List <string> rows = new List <string>();
            string        row  = "";

            T   entry = new T();
            var cols  = entry.GetType().GetProperties();

            foreach (var col in cols)
            {
                row += $",{col.Name}";
            }
            row = row.Substring(1);
            rows.Add(row);

            foreach (var item in items)
            {
                row = "";
                bool badWordDetected = false;

                foreach (var col in cols)
                {
                    string val = col.GetValue(item, null).ToString();

                    badWordDetected = BadWordDetector(val);

                    if (badWordDetected == true)
                    {
                        BadEntryFound?.Invoke(this, item);
                        break;
                    }
                    row += $",{val}";
                }

                if (badWordDetected == false)
                {
                    row = row.Substring(1);
                    rows.Add(row);
                }
            }

            File.WriteAllLines(filePath, rows);
        }