Patrick Smacchia [MVP C#]

Sponsors

The Lounge

Wicked Cool Jobs

News

  • NDepend v3 is fully integrated in Visual Studio, and is now available for download! Software dependencies visualization, 82 .NET software metrics, continuous rule validations, assembly version diff, declarative code queries and more ! http://ndepend.com

Advertisement

On Managing API

Normal 0 21 false false false FR X-NONE X-NONE

Recently, Jb Evain, the creator of Mono.Cecil, asked us if NDepend was using certain Cecil types or not (Cecil is a framework that reads/writes assemblies meta-data and NDepend relies on Cecil extensively). When one is hungry, it is better teaching him how to fish than feeding him with a fish. So I pointed him to this blog post on Controlling the usage of libraries with NDepend. Basically, I explained there that NDepend gather public members and types of tier assemblies used by the analyzed .NET code base. One can immediately browses what is used by its application. Thanks to the Dependency Matrix it is also easy to see which portion of the code is using which namespaces/types/members from an API.

 

 

Alternatively, to dig into the API usage one can also use a CQL query

 

SELECT METHODS FROM ASSEMBLIES "Mono.Cecil", "Mono.Cecil.Pdb" WHERE

IsDirectlyUsedBy "NDepend.Analysis.DotNet.CecilAnalyzer"

 

…conjointly with the new hierarchical capabilities of the Query Result panel…

 

 

…and eventually export the result to the matrix to dig further:

 

 

Exploring public API only

 

If you are in the position of editing a Framework, you certainly care about the public API exposed by your Framework. Doing so at source code level is pretty tedious because you don’t want to deal through the implementation but just with the public declarations in the code.

 

Here also the hierarchical capability of the Query Result panel is handy. When used conjointly with the Search by Visibility option, one can restraint the search to only public methods/fields/types:

 

 

Notice that the Search by Visibility option can be of great help in several others scenarios, especially when one wants to asses the optimal encapsulation level:

 

 

Detecting API breaking changes

 

Because NDepend can compare 2 different snapshots of a code base, it can also be used to detect and enforce API breaking changes. More details on this particular usage can be found here.

 

Evolution of API usage

 

Finally another API cool feature resulting from comparing 2 snapshots is the possibility to see which parts of an API is used only in the newer versions of your code (IsUsedRecently CQL condition) and which part was used in the older version but is not used anymore in the newer version (IsNotUsedAnymore CQL condition).

 

 

 


Posted Mon, Jul 13 2009 6:12 PM by Patrick Smacchia

[Advertisement]

Comments

Jason Haley wrote Interesting Finds: July 14, 2009
on Tue, Jul 14 2009 7:08 AM

Interesting Finds: July 14, 2009

DotNetShoutout wrote On Managing API - Patrick Smacchia - CodeBetter.Com
on Tue, Jul 14 2009 7:35 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us