【发布时间】:2014-01-27 18:50:06
【问题描述】:
我的 NDepend 报告警告说“非静态类应实例化或转为静态类。”返回列表中的大多数类都是通过我的 IOC 容器 (Unity) 注册的,并在运行时由我的 IOC 框架实例化。
鉴于 NDepend 正在执行静态分析,它不会意识到运行时实例化。我希望可以调整 CQL 以使其了解我的容器。
这是 NDepend 执行的样板查询:
warnif count > 0
from t in JustMyCode.Types
where t.IsClass &&
//!t.IsPublic && // if you are developping a framework,
// you might not want to match public classes
!t.IsStatic &&
!t.IsAttributeClass && // Attributes class are never seen as instantiated
!t.DeriveFrom("System.MarshalByRefObject".AllowNoMatch()) // Types instantiated through remoting infrstructure
// find the first constructor of t called
let ctorCalled = t.Constructors.FirstOrDefault(ctor => ctor.NbMethodsCallingMe > 0)
// match t if none of its constructors is called.
where ctorCalled == null
select new { t, t.Visibility }
我是否可以调整此查询以排除在我的 IOC 容器注册中引用的类?
【问题讨论】:
标签: ndepend