I'm trying to get a list of all the variables in a class. I'm trying to use reflection (which I've never used before) but it just doesn't make sense, and the docs aren't helping either. I feel like I'm making an obvious mistake, but I can't figure it out.
public override string ToString()
{
FieldInfo[] fields = GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
List<string> _return = new List<string>();
foreach (var field in fields)
{
_return.Add(field.Name + ": " + field.GetValue(field));
}
return _return;
}
The output is nothing.