System.ComponentModel.TypeDescriptor.FilterMembers C# (CSharp) Method

FilterMembers() private static method

This API is used to remove any members from the given collection that do not match the attribute array. If members need to be removed, a new ArrayList wil be created that contains only the remaining members. The API returns NULL if it did not need to filter any members.
private static FilterMembers ( IList members, Attribute attributes ) : ArrayList
members IList
attributes System.Attribute
return System.Collections.ArrayList
        private static ArrayList FilterMembers(IList members, Attribute[] attributes)
        {
            ArrayList newMembers = null;
            int memberCount = members.Count;

            for (int idx = 0; idx < memberCount; idx++)
            {
                bool hide = false;

                for (int attrIdx = 0; attrIdx < attributes.Length; attrIdx++)
                {
                    if (ShouldHideMember((MemberDescriptor)members[idx], attributes[attrIdx]))
                    {
                        hide = true;
                        break;
                    }
                }

                if (hide)
                {
                    // We have to hide.  If this is the first time, we need to init
                    // newMembers to have all the valid members we have previously
                    // hit.
                    if (newMembers == null)
                    {
                        newMembers = new ArrayList(memberCount);
                        for (int validIdx = 0; validIdx < idx; validIdx++)
                        {
                            newMembers.Add(members[validIdx]);
                        }
                    }
                }
                else if (newMembers != null)
                {
                    newMembers.Add(members[idx]);
                }
            }

            return newMembers;
        }