VS 2013 Ultimate 中的 Codelens 引用不正确 [英] Incorrect codelens references in VS 2013 ultimate

查看:43
本文介绍了VS 2013 Ultimate 中的 Codelens 引用不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是设计使然还是需要在 VS 2013 Ultimate 中启用/禁用功能,但 codelens 生成的引用计数完全不正常.它没有显示直接引用特定类/方法的类/方法的计数,而是显示整个解决方案中与类/方法同名的所有内容的计数.

I am not sure if this is by design or need to enable/disable features in VS 2013 ultimate but the reference counts generated by the codelens is completely out of whack. Instead of showing the count of classes/methods directly referencing a particular class/method, it shows the count of everything that has the same name as the class/method in the entire solution.

例如,假设我的解决方案中有四个类(四个项目每个类中有一个类无关紧要).

For example, say I have four classes in my solution (doesn't matter four projects with one class in each).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary20
{

    public interface IWillPrint
    {
        void PrintThis();
    }


    public class Class1 : IWillPrint
    {
        public void PrintThis() { }
    }

    public class Class2 : IWillPrint
    {
        public void PrintThis() { }
    }

    public class Class3 : IWillPrint
    {
        public void PrintThis() { }
    }

    public class Class4 : IWillPrint
    {
        public void PrintThis() { }
    }

    public class Class5
    {

        public void SomeMethod()
        {
            var j = new Class1();
            j.PrintThis();
        }
    }
}

class1 中方法 PrintThis() 的引用计数显示为 5.引用弹出窗口显示 class1、class2、class3、class4 和 class5 及其对应的行号:

The reference count for the method PrintThis() in class1 shows 5. The reference popup windows shows class1, class2, class3, class4 and class5 and their corresponding line numbers:

它应该在弹出窗口中只显示一个引用(1 个引用)和类 5.此外,我不确定为什么 codelens 还包含在计数中实际实现该方法的类.我现在看不到谁在打电话给谁.当你有很多类需要处理时,引用计数是一个很大的帮助.

It should show only one reference (1 reference) and class 5 in the popup. Also I am not sure why the codelens also includes the class that actually implements the method in the count. I am now unable to see who is calling who. The reference counts are a big help when you have lots of classes to deal with.

如果有更简单的解决方案,我不想重新安装 resharper 和/或 VS.

I would hate to reinstall the resharper and/or VS if there is a much simpler solution.

推荐答案

我在过去看到很多关于这个话题的讨论,当时这个功能正在开发中.我不得不在我的邮件档案中挖掘一下,看看是什么原因.官方的解释是这样的:

I've seen quite a bit of discussion on this topic in the past, while this feature was under development. I had to dig a bit in my mail archives to see what the reason was. The official explanation is this:

下面描述的内容绝对是按设计工作的,尽管从不同的角度来看它可能看起来是一个错误.本质上,Find All References 通过相关符号(例如虚拟方法、覆盖、接口实现等)级联,原因如下:

What’s described below is definitely working as designed, though it might seem a bug from a different perspective. In essence, Find All References cascades through related symbols (such as virtual methods, overrides, interface implementations, etc.) for a couple of reasons:

  1. 查找所有引用与重命名符号有内在联系.因此,如果您不希望破坏您的程序,这就是您需要包含在重命名符号操作中的一组符号.
  2. 如果不执行整个程序分析,visual studio 将无法确切知道程序执行时哪些方法真正是真正的引用.(无论如何这在现实中是不可能的......)此外,它并不确切知道您在寻找什么(也许您毕竟正在寻找派生方法),因此它呈现了整个集合.

随着越来越多的人使用 IoC/DI 框架,运行时替换的可能性越来越大,我个人发现寻找其他可能在运行时替换它的方法很有价值,但是当它们将被单独分组,以清楚地显示哪些方法是直接引用的,哪些是可替代的引用.

With more-and-more people using IoC/DI frameworks, substitution at runtime is more and more likely and I personally find great value in finding other methods that might be substituted in its place at runtime, but it would be great when they would be grouped separately to clearly show which method is directly referenced and which ones are substitutable-references.

也许references"是错误的名字,但我想Related Symbols"也会导致很多问题;)

Maybe "references" is the wrong name, but I suppose that "Related Symbols" would result in a lot of questions as well ;).

我知道无法在 CodeLens 中更改此行为,因此无论如何您可能都需要安装 Resharper,Visual Studio 用户语音,但我找不到.

I know of no way to change this behavior in CodeLens, so you may need to install Resharper anyway, there may already be an item for this on the Visual Studio User Voice, but I could not find it.

这篇关于VS 2013 Ultimate 中的 Codelens 引用不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆