***I sincerely apologise as I should have posted the complete code.
I have an application where I have an IUIAutomationElementArray and I have cached data regarding bounding rectangles of each IUIAutomationElement from the array. I am then converting these to WPF borders
public class NumberRectangle : Border, IComparable
{
currently I am using iteration to convert the IUIAutomationElementArray to an array list of rectangles seen in the method declaration below.
public ArrayList createRectangles(IUIAutomationElementArray elements)
{
// create an array list to hold the rectangles
rectArray = new ArrayList();
for (int i = 0; i < elements.Length; i++)
{
IUIAutomationElement currentElement = elements.GetElement(i);
//create DragonNumberRectangle to represent automation element
NumberRectangle currentRectangle = new NumberRectangle(currentElement);
//set horizontal and vertical alignment in order to align rectangles properly on window
currentRectangle.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
currentRectangle.VerticalAlignment = System.Windows.VerticalAlignment.Top;
currentRectangle.Height = (currentElement.CachedBoundingRectangle.bottom - currentElement.CachedBoundingRectangle.top);
currentRectangle.Width = (currentElement.CachedBoundingRectangle.right - currentElement.CachedBoundingRectangle.left);
// Thickness object represents Margin property of NumberRectangle (which is basically a Border)
Thickness rectThickness = new Thickness();
//set Left and Top for position of rectangle
rectThickness.Left = (currentElement.CachedBoundingRectangle.left);
rectThickness.Top = (currentElement.CachedBoundingRectangle.top);
currentRectangle.Margin = rectThickness;
// add colour rectangle to the list of rectangles
rectArray.Add(currentRectangle);
}
//sort the rectangles to number from left to right/top to bottom
rectArray.Sort();
return rectArray;
}
I then draw the borders on a WPF window. The issue is that the createRectangles metho takes one second of processing time where the conversion of the element array to rectangles is the predominant time waster.
So the question is can I do this with Linq and how would I do this with Linq, an example would be great as I am not familiar with Linq currently. Perhaps the real question is how do I speed this up?
ArrayList? There is no need to use it anymore, use generic lists.ArrayListis an artifact of .Net 1.0. You really should use the genericList<T>instead.forloop into Linq.