API: New publicly visible methods
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>
Open in the interactive Rules Explorer · All default rules
API Breaking Changes: all 9 items
- API Breaking Changes: Types ND1500
- API Breaking Changes: Methods ND1501
- API Breaking Changes: Fields ND1502
- API Breaking Changes: Interfaces and Abstract Classes ND1503
- Broken serializable types ND1504
- Avoid changing enumerations Flags status ND1505
- API: New publicly visible types
- API: New publicly visible methods
- API: New publicly visible fields