Rich Code Search Facilities


What the tremendous success of Google told us is that being able to find the right information quickly is essential. Here both Time spent searching and Relevancy of the result found are the important assets.

We, developers, spend a significant amount of time searching code elements in our code base. Every developer tools, including Visual Studio, come with some sort of search criteria. So let's focus on what makes the NDepend’s Code Rich Searching Experience unique.

Contrary to other tools, NDepend Code Search supports numerous criterias including Searching by Name, Size, Complexity, Coupling, Popularity, Coverage, Visibility, Mutability, Purity, Change and Coverage of Changes. Let's begin with what is certainly the most used criteria for searching in a code base, Search by Name.

▲▲ Go to Top ▲▲

Search by Name
    In Visual Studio, the two shortcuts Alt+M and Alt+C can be used to search Methods or Classes by name.

    Suppose one wants to search a click handler method but doesn’t remember where it is. The first step is searching for methods whose names include the sub-string "Click":

    Several things to notice here:
    • The Click keyword is highlighted in method result. This helps to spot more quickly the searched code element(s).
    • Method can be grouped by declaring assembly/namespace/type. This make the search much more efficient because in the general case, we have a clue of where the method searched should be declared.
    • Under the hood, the search is based on the CQLinq Query below, generated from the user inputs.
      from m in Methods 
      where m.NameLike (@"Click") 
      select new { m, m.NbLinesOfCode }

    ▲▲ Go to Top ▲▲

    Performance of Search

    Something that cannot be shown on screenshots is that NDepend search is fast, very fast: for example matching the 388.746 methods of the .NET Framework v4.0 that contain an "e" in the name is immediate.

    ▲▲ Go to Top ▲▲

    Multi Regex Support

    Let’s refine our search criteria. Suppose that the method to find, is a click event handler for a cancel button. Notice now the CQLinq Query generated that contains 2 NameLike clauses:
    from m in Methods 
    where m.NameLike (@"Click") && 
    m.NameLike (@"Cancel") 
    select new { m, m.NbLinesOfCode }

    More generally the CQLinq condition NameLike can be parameterized with any regular expression. You suddenly remember that your method should begin with "Cancel", upper case. Just click the lower case tick box and suffix your regex with ^, which means in regex terms begin with:

    ▲▲ Go to Top ▲▲

    Search Tier Code by Name

    The search can also easily include tier code elements. Clicking the Include Third-Party tickbox has for effect to discard the !IsThirdParty CQLinq restrictive condition.

    ▲▲ Go to Top ▲▲

    Search on Full Name

    Also, you can extend the search to the full name. In other words, one can match any method whose name, type or namespace contains "Click". For example, all methods declared in a class named like ToolClickedEventArg, are now matched.

    ▲▲ Go to Top ▲▲

    Refining Search by Name with CQLinq

    And because all this is based on CQLinq, you can easily edit the CQLinq Query generated and refine it at whim, like for example, to match static methods with "Click" in the name.

▲▲ Go to Top ▲▲

Search by other Criterias than Name

It is possible to search for methods, fields, types, namespaces and assemblies according to many other criterias than name. Keep in mind that in any case, all NDepend searching facilities are actually some CQLinq queries generator. So all the search criterias supported target particular CQLinq clauses.

▲▲ Go to Top ▲▲