Well, there are various ways of enumerating the properties, but I'm not
sure how that helps you validate things... you are going to have to find
some fun ways of validating arbitrary properties. That is why I
suggested IDataErrorInfo, as this provides a supported mechanism for an
object to validate *itself* and report any inconsistencies.
For enumerating the properties of an object, the simplest approach is
something like:
foreach(PropertyDescriptor prop in TypeDescriptor.GetProperties(obj))
{
Console.WriteLine("{0}={1}", prop.Name, prop.GetValue(obj));
}
However, note that PropertyGrid is a highly customisable control. For
example, it applies attribute-based filtering to properties (defaults to
[Browsable(true)], and allows individual tabs to shim other members as
properties - for example the "events" tab in VS.
Thus, if you have a complex setup, then to get the same list of
properties that PropertyGrid is using, you would have to do something like:
Attribute[] attribs =
new Attribute[grid.BrowsableAttributes.Count];
grid.BrowsableAttributes.CopyTo(attribs, 0);
foreach (PropertyDescriptor prop in
grid.SelectedTab.GetProperties(grid.SelectedObject, attribs))
{
Console.WriteLine("{0}={1}",
prop.Name, prop.GetValue(grid.SelectedObject));
}
But again - unless you have some metadata-based idea for validing
individual properties, I'm not sure how this is going to help you...
Marc