private static IList <PropertyDescriptor[]> UnsortedMerge(
                PropertyDescriptor[] baseEntries,
                IList <PropertyDescriptor[]> sortedMergedEntries)
            {
                List <PropertyDescriptor[]> mergedEntries = new();
                var mergeArray = new PropertyDescriptor[sortedMergedEntries[0].Length + 1];

                for (int i = 0; i < baseEntries.Length; i++)
                {
                    PropertyDescriptor basePropertyDescriptor = baseEntries[i];

                    // First do a binary search for a matching item.
                    PropertyDescriptor[] mergedEntryList = null;
                    string entryName = $"{basePropertyDescriptor.Name} {basePropertyDescriptor.PropertyType.FullName}";

                    int length = sortedMergedEntries.Count;

                    // Perform a binary search.
                    int offset = length / 2;
                    int start  = 0;

                    while (length > 0)
                    {
                        var propertyDescriptors = sortedMergedEntries[start + offset];
                        PropertyDescriptor propertyDescriptor = propertyDescriptors[0];
                        string             sortString         = $"{propertyDescriptor.Name} {propertyDescriptor.PropertyType.FullName}";
                        int result = string.Compare(entryName, sortString, ignoreCase: false, CultureInfo.InvariantCulture);
                        if (result == 0)
                        {
                            mergedEntryList = propertyDescriptors;
                            break;
                        }
                        else if (result < 0)
                        {
                            length = offset;
                        }
                        else
                        {
                            int delta = offset + 1;
                            start  += delta;
                            length -= delta;
                        }

                        offset = length / 2;
                    }

                    if (mergedEntryList is not null)
                    {
                        mergeArray[0] = basePropertyDescriptor;
                        Array.Copy(mergedEntryList, 0, mergeArray, 1, mergedEntryList.Length);
                        mergedEntries.Add((PropertyDescriptor[])mergeArray.Clone());
                    }
                }

                return(mergedEntries);
            }
示例#2
0
            private static ArrayList UnsortedMerge(PropertyDescriptor[] baseEntries, ArrayList sortedMergedEntries)
            {
                ArrayList mergedEntries = new ArrayList();

                PropertyDescriptor[] mergeArray = new PropertyDescriptor[((PropertyDescriptor[])sortedMergedEntries[0]).Length + 1];

                for (int i = 0; i < baseEntries.Length; i++)
                {
                    PropertyDescriptor basePd = baseEntries[i];

                    // first, do a binary search for a matching item
                    PropertyDescriptor[] mergedEntryList = null;
                    string entryName = basePd.Name + " " + basePd.PropertyType.FullName;

                    int len = sortedMergedEntries.Count;
                    // perform a binary search
                    int offset = len / 2;
                    int start  = 0;

                    while (len > 0)
                    {
                        PropertyDescriptor[] pdList = (PropertyDescriptor[])sortedMergedEntries[start + offset];
                        PropertyDescriptor   pd     = pdList[0];
                        string sortString           = pd.Name + " " + pd.PropertyType.FullName;
                        int    result = string.Compare(entryName, sortString, false, CultureInfo.InvariantCulture);
                        if (result == 0)
                        {
                            mergedEntryList = pdList;
                            break;
                        }
                        else if (result < 0)
                        {
                            len = offset;
                        }
                        else
                        {
                            int delta = offset + 1;
                            start += delta;
                            len   -= delta;
                        }

                        offset = len / 2;
                    }

                    if (mergedEntryList is not null)
                    {
                        mergeArray[0] = basePd;
                        Array.Copy(mergedEntryList, 0, mergeArray, 1, mergedEntryList.Length);
                        mergedEntries.Add(mergeArray.Clone());
                    }
                }

                return(mergedEntries);
            }
            private static ArrayList UnsortedMerge(PropertyDescriptor[] baseEntries, ArrayList sortedMergedEntries)
            {
                ArrayList list = new ArrayList();

                PropertyDescriptor[] destinationArray = new PropertyDescriptor[((PropertyDescriptor[])sortedMergedEntries[0]).Length + 1];
                for (int i = 0; i < baseEntries.Length; i++)
                {
                    PropertyDescriptor   descriptor  = baseEntries[i];
                    PropertyDescriptor[] sourceArray = null;
                    string strA  = descriptor.Name + " " + descriptor.PropertyType.FullName;
                    int    count = sortedMergedEntries.Count;
                    int    num3  = count / 2;
                    int    num4  = 0;
                    while (count > 0)
                    {
                        PropertyDescriptor[] descriptorArray3 = (PropertyDescriptor[])sortedMergedEntries[num4 + num3];
                        PropertyDescriptor   descriptor2      = descriptorArray3[0];
                        string strB = descriptor2.Name + " " + descriptor2.PropertyType.FullName;
                        int    num5 = string.Compare(strA, strB, false, CultureInfo.InvariantCulture);
                        if (num5 == 0)
                        {
                            sourceArray = descriptorArray3;
                            break;
                        }
                        if (num5 < 0)
                        {
                            count = num3;
                        }
                        else
                        {
                            int num6 = num3 + 1;
                            num4  += num6;
                            count -= num6;
                        }
                        num3 = count / 2;
                    }
                    if (sourceArray != null)
                    {
                        destinationArray[0] = descriptor;
                        Array.Copy(sourceArray, 0, destinationArray, 1, sourceArray.Length);
                        list.Add(destinationArray.Clone());
                    }
                }
                return(list);
            }
示例#4
0
            // this returns an array list of the propertydescriptor arrays, one for each
            // component
            //
            private static ArrayList GetCommonProperties(object[] objs, bool presort, PropertyTab tab, GridEntry parentEntry)
            {
                PropertyDescriptorCollection[] propCollections = new PropertyDescriptorCollection[objs.Length];

                Attribute[] attrs = new Attribute[parentEntry.BrowsableAttributes.Count];
                parentEntry.BrowsableAttributes.CopyTo(attrs, 0);

                for (int i = 0; i < objs.Length; i++)
                {
                    PropertyDescriptorCollection pdc = tab.GetProperties(parentEntry, objs[i], attrs);
                    if (presort)
                    {
                        pdc = pdc.Sort(PropertyComparer);
                    }
                    propCollections[i] = pdc;
                }

                ArrayList mergedList = new ArrayList();

                PropertyDescriptor[] matchArray = new PropertyDescriptor[objs.Length];

                //
                // Merge the property descriptors
                //
                int[] posArray = new int[propCollections.Length];
                for (int i = 0; i < propCollections[0].Count; i++)
                {
                    PropertyDescriptor pivotDesc = propCollections[0][i];

                    bool match = pivotDesc.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute();

                    for (int j = 1; match && j < propCollections.Length; j++)
                    {
                        if (posArray[j] >= propCollections[j].Count)
                        {
                            match = false;
                            break;
                        }

                        // check to see if we're on a match
                        //
                        PropertyDescriptor jProp = propCollections[j][posArray[j]];
                        if (pivotDesc.Equals(jProp))
                        {
                            posArray[j] += 1;

                            if (!jProp.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                            {
                                match = false;
                                break;
                            }
                            matchArray[j] = jProp;
                            continue;
                        }

                        int jPos = posArray[j];
                        jProp = propCollections[j][jPos];

                        match = false;

                        // if we aren't on a match, check all the items until we're past
                        // where the matching item would be
                        while (PropertyComparer.Compare(jProp, pivotDesc) <= 0)
                        {
                            // got a match!
                            if (pivotDesc.Equals(jProp))
                            {
                                if (!jProp.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                                {
                                    match = false;
                                    jPos++;
                                }
                                else
                                {
                                    match         = true;
                                    matchArray[j] = jProp;
                                    posArray[j]   = jPos + 1;
                                }
                                break;
                            }

                            // try again
                            jPos++;
                            if (jPos < propCollections[j].Count)
                            {
                                jProp = propCollections[j][jPos];
                            }
                            else
                            {
                                break;
                            }
                        }

                        // if we got here, there is no match, quit for this guy
                        if (!match)
                        {
                            posArray[j] = jPos;
                            break;
                        }
                    }

                    // do we have a match?
                    if (match)
                    {
                        matchArray[0] = pivotDesc;
                        mergedList.Add(matchArray.Clone());
                    }
                }

                return(mergedList);
            }
            private static ArrayList GetCommonProperties(object[] objects, bool presort, PropertyTab tab, GridEntry parentEntry)
            {
                var propertyCollections = new PropertyDescriptorCollection[objects.Length];
                var attributes          = new Attribute[parentEntry.BrowsableAttributes.Count];

                parentEntry.BrowsableAttributes.CopyTo(attributes, 0);

                for (int i = 0; i < objects.Length; i++)
                {
                    var properties = tab.GetProperties(parentEntry, objects[i], attributes);
                    if (presort)
                    {
                        properties = properties.Sort(s_propertyComparer);
                    }

                    propertyCollections[i] = properties;
                }

                ArrayList mergedList = new();
                var       matchArray = new PropertyDescriptor[objects.Length];

                //
                // Merge the property descriptors
                //

                int[] positions = new int[propertyCollections.Length];
                for (int i = 0; i < propertyCollections[0].Count; i++)
                {
                    PropertyDescriptor pivotProperty = propertyCollections[0][i];

                    bool match = pivotProperty.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute();

                    for (int j = 1; match && j < propertyCollections.Length; j++)
                    {
                        if (positions[j] >= propertyCollections[j].Count)
                        {
                            match = false;
                            break;
                        }

                        // Check to see if we're on a match.
                        PropertyDescriptor property = propertyCollections[j][positions[j]];
                        if (pivotProperty.Equals(property))
                        {
                            positions[j] += 1;

                            if (!property.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                            {
                                match = false;
                                break;
                            }

                            matchArray[j] = property;
                            continue;
                        }

                        int position = positions[j];
                        property = propertyCollections[j][position];

                        match = false;

                        // If we aren't on a match, check all the items until we're past where the matching item would be.
                        while (s_propertyComparer.Compare(property, pivotProperty) <= 0)
                        {
                            // Got a match!
                            if (pivotProperty.Equals(property))
                            {
                                if (!property.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                                {
                                    match = false;
                                    position++;
                                }
                                else
                                {
                                    match         = true;
                                    matchArray[j] = property;
                                    positions[j]  = position + 1;
                                }

                                break;
                            }

                            // Try again.
                            position++;
                            if (position < propertyCollections[j].Count)
                            {
                                property = propertyCollections[j][position];
                            }
                            else
                            {
                                break;
                            }
                        }

                        // If we got here, there is no match, quit for this one.
                        if (!match)
                        {
                            positions[j] = position;
                            break;
                        }
                    }

                    // Do we have a match?
                    if (match)
                    {
                        matchArray[0] = pivotProperty;
                        mergedList.Add(matchArray.Clone());
                    }
                }

                return(mergedList);
            }
            private static ArrayList GetCommonProperties(object[] objs, bool presort, PropertyTab tab, GridEntry parentEntry)
            {
                PropertyDescriptorCollection[] descriptorsArray = new PropertyDescriptorCollection[objs.Length];
                Attribute[] array = new Attribute[parentEntry.BrowsableAttributes.Count];
                parentEntry.BrowsableAttributes.CopyTo(array, 0);
                for (int i = 0; i < objs.Length; i++)
                {
                    PropertyDescriptorCollection descriptors = tab.GetProperties(parentEntry, objs[i], array);
                    if (presort)
                    {
                        descriptors = descriptors.Sort(MultiSelectRootGridEntry.PropertyComparer);
                    }
                    descriptorsArray[i] = descriptors;
                }
                ArrayList list = new ArrayList();

                PropertyDescriptor[] descriptorArray = new PropertyDescriptor[objs.Length];
                int[] numArray = new int[descriptorsArray.Length];
                for (int j = 0; j < descriptorsArray[0].Count; j++)
                {
                    PropertyDescriptor descriptor = descriptorsArray[0][j];
                    bool flag = descriptor.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute();
                    for (int k = 1; flag && (k < descriptorsArray.Length); k++)
                    {
                        if (numArray[k] >= descriptorsArray[k].Count)
                        {
                            flag = false;
                            break;
                        }
                        PropertyDescriptor descriptor2 = descriptorsArray[k][numArray[k]];
                        if (descriptor.Equals(descriptor2))
                        {
                            numArray[k]++;
                            if (!descriptor2.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                            {
                                flag = false;
                                break;
                            }
                            descriptorArray[k] = descriptor2;
                            continue;
                        }
                        int num4 = numArray[k];
                        descriptor2 = descriptorsArray[k][num4];
                        flag        = false;
                        while (MultiSelectRootGridEntry.PropertyComparer.Compare(descriptor2, descriptor) <= 0)
                        {
                            if (descriptor.Equals(descriptor2))
                            {
                                if (!descriptor2.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                                {
                                    flag = false;
                                    num4++;
                                }
                                else
                                {
                                    flag = true;
                                    descriptorArray[k] = descriptor2;
                                    numArray[k]        = num4 + 1;
                                }
                                break;
                            }
                            num4++;
                            if (num4 >= descriptorsArray[k].Count)
                            {
                                break;
                            }
                            descriptor2 = descriptorsArray[k][num4];
                        }
                        if (!flag)
                        {
                            numArray[k] = num4;
                            break;
                        }
                    }
                    if (flag)
                    {
                        descriptorArray[0] = descriptor;
                        list.Add(descriptorArray.Clone());
                    }
                }
                return(list);
            }