Method should not return concrete XmlNode
Warns about methods returning System.Xml.XmlNode or a derived type. XmlNode implements System.Xml.Xpath.IXPathNavigable; returning the interface usually abstracts client code from implementation details.
How to fix
Return IXPathNavigable instead and refactor client code if possible.
CQLinq source
This rule 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>Method should not return concrete XmlNode</Name>
// <Id>ND2600:MethodShouldNotReturnConcreteXmlNode</Id>
warnif count > 0
let xmlNode = ThirdParty.Types.WithFullName("System.Xml.XmlNode")
let concreteXmlTypes = ThirdParty.Types.ThatDeriveFromAny(xmlNode)
.Concat(xmlNode)
from m in Application.Methods.WithReturnTypeIn(concreteXmlTypes)
select new {
m,
m.ReturnType,
Debt = 10.ToMinutes().ToDebt(),
Severity = Severity.Medium
}
//<Expl>
// The *{0}* should not return *concrete {1}*.
// Return instead the *interface IXPathNavigable*
// to shield client code from specific implementation details.
//</Expl>
//<Desc>
// Warns about methods returning **System.Xml.XmlNode** or a derived type.
// *XmlNode* implements **System.Xml.Xpath.IXPathNavigable**; returning the
// interface usually abstracts client code from implementation details.
//</Desc>
//<HowToFix>
// Return *IXPathNavigable* instead and refactor client code if possible.
//</HowToFix>
Open in the interactive Rules Explorer · All default rules
.NET Framework Usage / System.Xml: all 2 items
- Method should not return concrete XmlNode ND2600
- Types should not derive from System.Xml.XmlDocument ND2601