【发布时间】: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