Get All Properties - CSharp System.Reflection

CSharp examples for System.Reflection:PropertyInfo

Description

Get All Properties

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w  w  w.j av  a 2 s . c om*/

public class Main{
        public static IEnumerable<PropertyInfo> GetAllProperties(this Type type)
        {
            var typeInfo = type.GetTypeInfo();
            var properties = typeInfo.DeclaredProperties;

            var baseType = typeInfo.BaseType;

            return baseType == null ? properties : properties.Concat(baseType.GetAllProperties());
        }
}

Related Tutorials