【问题标题】:NDepend: Find fields that are either a given type or use a given type in their generic parametersNDepend:查找给定类型或在其泛型参数中使用给定类型的字段
【发布时间】:2020-10-26 20:26:46
【问题描述】:

我将如何使用 NDepend 来不仅识别JustMyCode.Fields完全 给定类型,而且间接识别,即像 IList<MyType>IDictionary<int, MyType>Lazy<T> 和所有那些“不错”的通用变体/用法?

是否有任何类似于.UsedBy(...) 的辅助方法可以提供这样的功能?

【问题讨论】:

    标签: ndepend


    【解决方案1】:

    这是一个查询以获取使用StringInt32 键入的字段:

    let types = Types.WithFullNameIn(
       "System.String", 
       "System.Int32").ToArray()
    from f in Application.Fields
    where !f.ParentType.IsEnumeration &&
           f.FieldType != null &&
           types.Contains(f.FieldType)
    select new { f, type =f.FieldType }
    

    目前您无法检测到泛型参数中何时使用了类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多