Essential C# Reflection  Suggest an edit

Looping through all the properties of a class

Type type = obj.GetType();
// To restrict return properties. If all properties are required don't provide flag.
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; 
PropertyInfo[] properties = type.GetProperties(flags);

foreach (PropertyInfo property in properties)
{
    Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(obj, null));
}

Table Of Contents
22 Enum
25 GUID
62 Reflection
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close