jeudi 2 juillet 2020

Read all rows and properties from List

    public string ClassListToText<T>(List<T> obj)
    {
        StringBuilder str = new StringBuilder();
        PropertyInfo[] properties = typeof(T).GetProperties();
        foreach(PropertyInfo property in properties)
        {
            str.Append(property.Name + "|");
        }
        str.Append(">>");

        foreach (T row in obj)
        {
            string txtRow = string.Empty;
            foreach (PropertyInfo property in properties)
            {
                txtRow += row[property.Name].ToString().Trim();
                txtRow += "|";
            }
            txtRow += ">";
            str.AppendLine(txtRow);

        }
        return str.ToString();
    }

I would like to read all List rows and properties and write it to text file. I can't find how to do this part of code "row[property.Name]"?





Aucun commentaire:

Enregistrer un commentaire