Finds the properties. - CSharp System.Reflection

CSharp examples for System.Reflection:PropertyInfo

Description

Finds the properties.

Demo Code


using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System;/*from w ww .j a  v a  2s .co  m*/

public class Main{
        /// <summary>
        /// Finds the properties.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static PropertyInfo[] FindProperties(Type type)
        {
            // get all public static properties of MyClass type
            PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            // sort properties by name
            Array.Sort(propertyInfos,
                    delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
                    { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); });

            return propertyInfos;
        }
}

Related Tutorials