Esempio n. 1
0
        /// <summary>
        /// Gets all properties.
        /// </summary>
        /// <param name="type">
        /// The declaring type.
        /// </param>
        /// <param name="bindingAttributes">
        /// The binding attributes.
        /// </param>
        /// <returns>
        /// The IEnumerable of properties.
        /// </returns>
        public static IEnumerable <PropertyInfo> GetAllProperties(Type type, BindingFlags bindingAttributes)
        {
            Dictionary <MetaPosition, PropertyInfo> dictionary = new Dictionary <MetaPosition, PropertyInfo>();
            Type baseType = type;

            do
            {
                foreach (PropertyInfo info in baseType.GetProperties(bindingAttributes))
                {
                    if ((type == baseType) || IsPrivate(info))
                    {
                        MetaPosition position = new MetaPosition(info);
                        dictionary[position] = info;
                    }
                }

                baseType = baseType.BaseType;
            }while (baseType != null);
            return(dictionary.Values);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets all fields.
        /// </summary>
        /// <param name="type">
        /// The declaring type.
        /// </param>
        /// <param name="bindingAttributes">
        /// The binding attributes.
        /// </param>
        /// <returns>
        /// IEnumerable of fields.
        /// </returns>
        public static IEnumerable <FieldInfo> GetAllFields(Type type, BindingFlags bindingAttributes)
        {
            Dictionary <MetaPosition, FieldInfo> dictionary = new Dictionary <MetaPosition, FieldInfo>();
            Type baseType = type;

            do
            {
                foreach (FieldInfo info in baseType.GetFields(bindingAttributes))
                {
                    if (info.IsPrivate || (type == baseType))
                    {
                        MetaPosition position = new MetaPosition(info);
                        dictionary[position] = info;
                    }
                }

                baseType = baseType.BaseType;
            }while (baseType != null);
            return(dictionary.Values);
        }