【问题标题】:Rule S1144 "Remove unused private method" c# - VS 2015规则 S1144“删除未使用的私有方法”c# - VS 2015
【发布时间】:2017-03-02 14:25:20
【问题描述】:

方法 Visit(Leaf v)Visit(Composite v) 被 SonarLint 标记为未使用。 SonarQube 也将其标记为未使用。但它以动态方式调用。 有人知道如何解决吗?可能有一些配置? 入口点是一个Visit(Base root),然后使用动态调用它会遍历树。

UPD:更新示例

这是示例:

public void Visit(Base root)
{
   Visit((dynamic)root);
}

private void Visit(Composite v )
{
    v.Children.ForEach(el => Visit((dynamic)el));
}

private void Visit(Leaf v)
{
    // do smth
}

class Base
{
} 

class Composite : Base
{
    public IEnumerable<Base> Children { get;}
}

class Leaf : Base
{

}

【问题讨论】:

  • 你能告诉我们你调用Visit的代码吗?
  • @dotctor 是的,srry 入口点错误,更新了代码。这是轻样本。但是在 v.Children.ForEach(el => Visit((dynamic)el)); 中也调用了 Visit((dynamic)el));
  • @mybirthname 移除声纳 - 这不是案例或解决方案

标签: c# sonarqube sonarlint


【解决方案1】:

这是 SonarLint 中的误报。目前没有解决这个问题。当我们解析方法引用时,我们可能应该使用CandidateSymbols。我在这里为它创建了一张票:https://jira.sonarsource.com/browse/SLVS-1080

【讨论】:

    猜你喜欢
    • 2016-12-02
    • 1970-01-01
    • 2015-11-11
    • 2016-08-27
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多