public PropertyGridMember IncludeMember(string memberToInclude, Type type, MemberChangeEventHandler memberChangeAction, Func <object> getMember, TypeConverter converter = null, Attribute[] attributes = null)
        {
            if (mNativePropertyGridMembers.ContainsMember(memberToInclude))
            {
                mNativePropertyGridMembers.RemoveMember(memberToInclude);
            }

            PropertyGridMember pgm = new PropertyGridMember();

            pgm.MemberChange    = memberChangeAction;
            pgm.CustomGetMember = getMember;
            pgm.Name            = memberToInclude;
            pgm.Type            = type;
            pgm.TypeConverter   = converter;
            pgm.Attributes.Clear();

            if (attributes != null)
            {
                pgm.Attributes.AddRange(attributes);
            }

            if (getMember != null && memberChangeAction == null)
            {
                pgm.IsReadOnly = true;
                pgm.Attributes.Add(new ReadOnlyAttribute(true));
            }

            mCustomPropertyGridMembers.Add(pgm);

            return(pgm);
        }
        private void UpdateProperties()
        {
            if (mInstance != null)
            {
                // This only removes
                // native members that
                // haven't been explicitly
                // added.  Explicitly-added
                // members may have TypeConverters
                // so we want to preserve those.
                ClearNonExplicitNativeMembers();

                PropertyInfo[] propertyInfos = mInstance.GetType().GetProperties(

                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty // I don't think we want to show static members in PropertyGrids
                    );

                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    if (!mExcludedMembers.Contains(propertyInfo.Name) && !mCustomPropertyGridMembers.ContainsMember(propertyInfo.Name))
                    {
                        PropertyGridMember pgm = new PropertyGridMember();
                        pgm.Name = propertyInfo.Name;
                        pgm.Type = propertyInfo.PropertyType;

                        pgm.SetAttributes(propertyInfo.GetCustomAttributes(true));
                        pgm.IsReadOnly = propertyInfo.CanWrite == false;
                        // Does this thing have a type converter set on the property?
                        TypeConverterAttribute attrib =
                            (TypeConverterAttribute)Attribute.GetCustomAttribute(propertyInfo,
                                                                                 typeof(TypeConverterAttribute));
                        if (attrib != null)
                        {
                            TypeConverter converter =
                                (TypeConverter)Activator.CreateInstance(Type.GetType(attrib.ConverterTypeName),
                                                                        false);
                            pgm.TypeConverter = converter;
                        }

                        mNativePropertyGridMembers.Add(pgm);
                    }
                }

                FieldInfo[] fieldInfos = mInstance.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField);
                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    if (!mExcludedMembers.Contains(fieldInfo.Name) && !mCustomPropertyGridMembers.ContainsMember(fieldInfo.Name))
                    {
                        PropertyGridMember pgm = new PropertyGridMember()
                        {
                            Name = fieldInfo.Name,
                            Type = fieldInfo.FieldType
                        };

                        mNativePropertyGridMembers.Add(pgm);
                    }
                }
            }
        }
        private void UpdateProperties()
        {
            if (mInstance != null)
            {
                // This only removes
                // native members that
                // haven't been explicitly
                // added.  Explicitly-added
                // members may have TypeConverters
                // so we want to preserve those.
                ClearNonExplicitNativeMembers();

                PropertyInfo[] propertyInfos = mInstance.GetType().GetProperties(
                    
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty // I don't think we want to show static members in PropertyGrids
                    );

                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    if (!mExcludedMembers.Contains(propertyInfo.Name) && !mCustomPropertyGridMembers.ContainsMember(propertyInfo.Name))
                    {
                        PropertyGridMember pgm = new PropertyGridMember();
                        pgm.Name = propertyInfo.Name;
                        pgm.Type = propertyInfo.PropertyType;

                        pgm.SetAttributes(propertyInfo.GetCustomAttributes(true));
                        pgm.IsReadOnly = propertyInfo.CanWrite == false;
                        // Does this thing have a type converter set on the property?
                        TypeConverterAttribute attrib =
                            (TypeConverterAttribute)Attribute.GetCustomAttribute(propertyInfo,
                            typeof(TypeConverterAttribute));
                        if (attrib != null)
                        {
                            TypeConverter converter =
                                (TypeConverter)Activator.CreateInstance(Type.GetType(attrib.ConverterTypeName),
                                false);
                            pgm.TypeConverter = converter;
                        }

                        mNativePropertyGridMembers.Add(pgm);
                    }
                }

                FieldInfo[] fieldInfos = mInstance.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField);
                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    if (!mExcludedMembers.Contains(fieldInfo.Name) && !mCustomPropertyGridMembers.ContainsMember(fieldInfo.Name))
                    {
                        PropertyGridMember pgm = new PropertyGridMember()
                        {
                            Name = fieldInfo.Name,
                            Type = fieldInfo.FieldType

                        };

                        mNativePropertyGridMembers.Add(pgm);
                    }
                }
            }

        }
        public void IncludeMember(string memberToInclude, Type containingType = null, TypeConverter typeConverter = null, object[] attributes = null)
        {
            if (mExcludedMembers.Contains(memberToInclude))
            {
                mExcludedMembers.Remove(memberToInclude);
            }

            if (typeConverter != null || attributes != null)
            {
                if (containingType == null)
                {
                    throw new Exception("The containingType must not be null when passing a type converter");
                }
                else
                {
                    Type     memberType         = null;
                    object[] attributesFromType = null;


                    FieldInfo fieldInfo = containingType.GetField(memberToInclude);
                    if (fieldInfo != null)
                    {
                        memberType         = fieldInfo.FieldType;
                        attributesFromType = fieldInfo.GetCustomAttributes(true);
                    }
                    else
                    {
                        PropertyInfo propertyInfo = containingType.GetProperty(memberToInclude);

                        if (propertyInfo != null)
                        {
                            memberType         = propertyInfo.PropertyType;
                            attributesFromType = propertyInfo.GetCustomAttributes(true);
                        }
                    }

                    int count = attributesFromType.Length;
                    if (attributes != null)
                    {
                        count += attributes.Length;
                    }

                    List <Attribute> allList = new List <Attribute>(count);
                    foreach (var item in attributesFromType)
                    {
                        allList.Add(item as Attribute);
                    }
                    if (attributes != null)
                    {
                        foreach (var item in attributes)
                        {
                            allList.Add(item as Attribute);
                        }
                    }

                    if (memberType == null)
                    {
                        throw new Exception("Could not find member " + memberToInclude + " in type " + containingType);
                    }
                    else
                    {
                        PropertyGridMember pgm = IncludeMember(memberToInclude, memberType, null, null, typeConverter, null);
                        pgm.SetAttributes(allList.ToArray());
                    }
                }
            }

            UpdateProperties();
        }
        public PropertyGridMember IncludeMember(string memberToInclude, Type type, MemberChangeEventHandler memberChangeAction, Func<object> getMember, TypeConverter converter = null, Attribute[] attributes = null)
        {
            if (mNativePropertyGridMembers.ContainsMember(memberToInclude))
            {
                mNativePropertyGridMembers.RemoveMember(memberToInclude);
            }

            PropertyGridMember pgm = new PropertyGridMember();
            pgm.MemberChange = memberChangeAction;
            pgm.CustomGetMember = getMember;
            pgm.Name = memberToInclude;
            pgm.Type = type;
            pgm.TypeConverter = converter;
            pgm.Attributes.Clear();

            if (attributes != null)
            {
                pgm.Attributes.AddRange(attributes);
            }

            if (getMember != null && memberChangeAction == null)
            {
                pgm.IsReadOnly = true;
                pgm.Attributes.Add(new ReadOnlyAttribute(true));
            }

            mCustomPropertyGridMembers.Add(pgm);

            return pgm;
        }