Something like this:
var values = instance.GetType().GetProperties().Select(x => x.GetValue(instance, null));
If you also want the name of the property use this:
var values = instance.GetType().GetProperties().Select(x =>
new
{
property = x.Name,
value = x.GetValue(instance, null)
})
.ToDictionary(x => x.property, y => y.value);
This selects all the properties of the given type and gets its name and value for the desired instance.
However this approach only works for simple, non-indexed properties.
EDIT: Also have a look on MSDN on Bindingflags to restrict the properties returned from GetType().GetProperties
- in particular when you need the properties of your base-class also.