protected void InternalSort(string[] names) {
if (properties == null || properties.Length == 0) {
return;
}
this.InternalSort(this.comparer);
if (names != null && names.Length > 0) {
ArrayList propArrayList = new ArrayList(properties);
int foundCount = 0;
int propCount = properties.Length;
for (int i = 0; i < names.Length; i++) {
for (int j = 0; j < propCount; j++) {
PropertyDescriptor currentProp = (PropertyDescriptor)propArrayList[j];
// Found a matching property. Here, we add it to our array. We also
// mark it as null in our array list so we don't add it twice later.
//
if (currentProp != null && currentProp.Name.Equals(names[i])) {
properties[foundCount++] = currentProp;
propArrayList[j] = null;
break;
}
}
}
// At this point we have filled in the first "foundCount" number of propeties, one for each
// name in our name array. If a name didn't match, then it is ignored. Next, we must fill
// in the rest of the properties. We now have a sparse array containing the remainder, so
// it's easy.
//
for (int i = 0; i < propCount; i++) {
if (propArrayList[i] != null) {
properties[foundCount++] = (PropertyDescriptor)propArrayList[i];
}
}
Debug.Assert(foundCount == propCount, "We did not completely fill our property array");
}
}