in
Forums
Blogs
Files
Devexpress.Com
ClientCenter
Support Center
DevExpress Channel

iterating elements of a solution

Last post 8/21/2008 1:21 PM by Mark Miller (Developer Express). 1 replies.
Page 1 of 1 (2 items)
Sort Posts:
Previous Next
  • 8/20/2008 4:48 PM

    iterating elements of a solution

    I have a plugin that is attempting to iterate through the language elements(initially just classes) of a solution.  This generally works pretty well, but on a fairly large solution(5500 cs files and 34 projects) I start getting "out of memory" exceptions while iterating through the elements.

    My code looks something like the following:


          int itemCounter = 0;
          int classCounter = 0;
          SolutionElement sol = CodeRush.Source.ActiveProject.Solution;

          foreach (LanguageElement item in sol.AllTypes)
          {
            itemCounter++;
            if (item.ElementType == LanguageElementType.Class)
            {    
              classCounter++;
            }
          }

    My counters reliably end up at  3543 classes and 4897 items when the exception occurs.


    Is this the preffered way of iterating through language elements or is there a more efficient way?  QuickNav must be doing something similar and it seems to work on this large project.

      
    thanks,

    randall

     

  • 8/21/2008 1:21 PM In reply to

    Re: iterating elements of a solution

    Hi Randall,

    Can you please report this to support center so we can assign a dev to this?

    We suspect the AllTypes property is leading to unecessary parsing that isn't releasing memory during the iteration, and in large projects you're feeling the hit. We will fix this, but as a work around, try code like this:

    public static void GetTypeCountsForProject(ProjectElement proj, out int itemCounter, out int classCounter)
    {
      itemCounter =
    0
    ;
      classCounter =
    0
    ;
      System.Collections.
    ICollection
    liteElements = proj.ProjectSymbols.Values;

      foreach (IElement element in
    liteElements)
        if (element is ITypeElement
    )
        {
          itemCounter++;
         
    if (element.ElementType == LanguageElementType
    .Class)
            classCounter++;
        }
    }

     

    The lite elements are something that we don't normally expose to plug-in developers -- they are a lightweight structure we use behind the scenes to support some of the heavier elements like LanguageElement and its descendants.

Page 1 of 1 (2 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED