Have a "User class" in my C# project for wich i would like to store all variables in an text file - All goes fine until i come to a list of "to do" list that is included in the user class. The User class also includes a couple of more lists
So the question is, how do i cycle through all variables in an object, and all variables in the included lists?
The code i got so far:
StreamWriter File = new StreamWriter(Sökväg);
var props = this.GetType().GetProperties();
foreach (var prop in props)
{
object value = prop.GetValue(this, null); // against prop.Name
if (value != null)
{
switch (prop.PropertyType.ToString())
{
case "System.String":
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.DateTime":
case "System.Boolean":
File.WriteLine(prop.Name + "|" + value.ToString());
break;
default:
MessageBox.Show("Property type not supported" +
Environment.NewLine + prop.Name);
break;
}
}
}
File.Close();