public void CopyTest(int count, int index) { var attributes = GetAttributes().Take(count).ToArray(); var attributeCollection = new AttributeCollection(attributes); var array = new Attribute[count + index]; attributeCollection.CopyTo(array, index); Assert.Equal(attributeCollection.Cast<Attribute>(), array.Cast<Attribute>().Skip(index)); }
internal Attribute[] GetAttributesFromCollection(AttributeCollection collection) { Attribute[] attributes = new Attribute[collection.Count]; collection.CopyTo(attributes, 0); return(attributes); }
private Attribute[] GetAttributesFromCollection(AttributeCollection collection) { Attribute[] array = new Attribute[collection.Count]; collection.CopyTo(array, 0); return(array); }
private void FullMerge() { Attribute[][] collections = new Attribute[owner.descriptors.Length][]; for (int i = 0; i < owner.descriptors.Length; i++) { AttributeCollection attrCollection = owner.descriptors[i].Attributes; collections[i] = new Attribute[attrCollection.Count]; attrCollection.CopyTo(collections[i], 0); Array.Sort(collections[i], GridEntry.AttributeTypeSorter); } ArrayList mergedList = new ArrayList(); // merge the sorted lists -- note that lists aren't fully sorted just by // Attribute.TypeId // int[] posArray = new int[collections.Length]; for (int i = 0; i < collections[0].Length; i++) { Attribute pivotAttr = collections[0][i]; bool match = true; for (int j = 1; j < collections.Length; j++) { if (posArray[j] >= collections[j].Length) { match = false; break; } // check to see if we're on a match // if (pivotAttr.Equals(collections[j][posArray[j]])) { posArray[j] += 1; continue; } int jPos = posArray[j]; Attribute jAttr = collections[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 (GridEntry.AttributeTypeSorter.Compare(jAttr, pivotAttr) <= 0) { // got a match! if (pivotAttr.Equals(jAttr)) { posArray[j] = jPos + 1; match = true; break; } // try again jPos++; if (jPos < collections[j].Length) { jAttr = collections[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) { mergedList.Add(pivotAttr); } } // create our merged array Attribute[] mergedAttrs = new Attribute[mergedList.Count]; mergedList.CopyTo(mergedAttrs, 0); }
/// <summary> /// Creates an Attribute array from an AttributeCollection instance /// </summary> /// <param name="collection"></param> /// <returns></returns> private static Attribute[] AttributeCollectionToArray(AttributeCollection collection) { Attribute[] array = new Attribute[collection.Count]; collection.CopyTo(array, 0); return(array); }