Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

get all properties of an object including children c#

private void DisplayObject(object obj)
{
    var type = obj.GetType();
    foreach(var propertyInfo in type.GetProperties())
    {
        object value = propertyInfo.GetValue(obj, null);
        if(propertyInfo.PropertyType.IsGenericType && 
            propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
        {
            foreach(object o in (IEnumerable)value)
            {
                DisplayObject(o);
            }
        }
        else
        {
            Console.WriteLine(value);
        }
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #properties #object #including #children
ADD COMMENT
Topic
Name
6+8 =