System.Windows.Forms.ListBindingHelper.GetListItemPropertiesByInstance C# (CSharp) Method

GetListItemPropertiesByInstance() private static method

private static GetListItemPropertiesByInstance ( object target, Array listAccessors, int startIndex ) : System.Windows.Forms.PropertyDescriptorCollection
target object
listAccessors Array
startIndex int
return System.Windows.Forms.PropertyDescriptorCollection
        private static PropertyDescriptorCollection GetListItemPropertiesByInstance(object target, PropertyDescriptor[] listAccessors, int startIndex) {
            // At this point, things can be simplified because:
            //   We know target is _not_ a list
            //   We have an instance

            PropertyDescriptorCollection pdc;

            // Get the value of the first listAccessor
            if (listAccessors != null && listAccessors.Length > startIndex) {
                // Get the value (e.g. given Foo with property Bar, this gets Foo.Bar)
                object value = listAccessors[startIndex].GetValue(target);

                if (value == null) {
                    // It's null - we can't walk down by Instance so use Type
                    pdc = GetListItemPropertiesByType(listAccessors[startIndex].PropertyType, listAccessors, startIndex);
                }
                else {
                    PropertyDescriptor[] accessors = null;

                    if (listAccessors.Length > startIndex + 1) {
                        int accessorsCount = listAccessors.Length - (startIndex + 1);
                        accessors = new PropertyDescriptor[accessorsCount];
                        for (int i = 0; i < accessorsCount; ++i) {
                            accessors[i] = listAccessors[startIndex + 1 + i];
                        }
                    }

                    // We've got the instance of Bar - now get it's shape
                    pdc = GetListItemProperties(value, accessors);
                }
            }
            else {
                // Fallback to TypeDescriptor
                pdc = TypeDescriptor.GetProperties(target, BrowsableAttributeList);
            }

            return pdc;
        }