【问题标题】:How to get Resharper to show a Refactoring that it already has如何让 Resharper 显示它已经拥有的重构
【发布时间】:2011-01-08 00:57:41
【问题描述】:

每当 Resharper 遇到这样的代码时:

(treeListNode.Tag as GridLine).AdvertiserSeparation = 5;

它为您提供了一个可能的修复方法(因为 treeListNode.Tag as GridLine 可能为空)。它说:“替换为直接投射”,这会将代码变成以下内容:

((GridLine) treeListNode.Tag).AdvertiserSeparation = 5;

这太棒了。但是,当它遇到这样的代码时:

GridLine line = treeListNode.Tag as GridLine;
line.AdvertiserSeparation = 5;

Resharper 只是显示警告“可能的 System.NullReferenceException”,但没有让我“用直接投射替换”。有没有办法让 Resharper 为我提供这种重构,因为它已经有了它?

【问题讨论】:

    标签: visual-studio-2008 refactoring resharper directcast


    【解决方案1】:

    在第一种情况下,异常在表达式中,修复也在表达式中。因此,修复程序可用。在第二种情况下,异常是在基于变量的赋值行上,但修复是在不相关的表达式中。因此,Resharper 不会在此处提供修复程序。

    不过,Jetbrains 的人反应迅速,因此您可以记录一个案例。

    http://www.jetbrains.net/jira/browse/RSRP

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 2015-10-25
      • 2012-04-05
      • 1970-01-01
      • 2019-01-20
      • 2015-06-15
      • 1970-01-01
      • 2023-01-07
      • 1970-01-01
      相关资源
      最近更新 更多