API: New publicly visible methods

Code Query API Breaking Changes

Runs only in diff mode (baseline defined). Lists methods new in the public surface of the analyzed assemblies.

CQLinq source

This code query is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>API: New publicly visible methods</Name>
from m in Application.Methods
where m.IsPubliclyVisible && 

     // The method has been removed and its parent assembly hasn't been removed …
     ( (m.WasAdded() && !m.ParentType.WasAdded()) ||

     // … or the method existed but was not publicly visible
       !m.WasAdded() && !m.OlderVersion().IsPubliclyVisible)

//--------------------------------------
// Handle special case: if between two versions a regular property becomes 
// an auto-property (or vice-versa) the property getter/setter method have 
// a different value for IMethod.IsGeneratedByCompiler
// since auto-property getter/setter are marked as generated by the compiler.
//
// If a method IsGeneratedByCompiler value changes between two versions, 
// NDepend doesn't pair the newer/older occurences of the method.
//
// Hence in such situation, a public method is seen as added 
// and a public method is seen as removed, but the API is not broken!
// The equivalentMethod-check below avoids reporting such 
// API Breaking Change false-positive.
let equivalentMethod = m.WasAdded() && m.ParentType.IsPresentInBothBuilds() ?
   m.ParentType.OlderVersion().Methods
   .FirstOrDefault(m1 => 
       m1.IsPubliclyVisible &&
       m1.Name == m.Name &&
       m1.IsGeneratedByCompiler != m.IsGeneratedByCompiler)
    : null
where equivalentMethod == null
//--------------------------------------

select new { 
   m,
   OldVisibility = 
      (m.WasAdded() ? " " : 
       m.OlderVersion().Visibility.ToString())
}

//<Desc>
// Runs only in *diff mode* (baseline defined). Lists methods new in the
// public surface of the analyzed assemblies.
//</Desc>

API Breaking Changes: all 9 items