可以先给Visual Studio的C#intellisense提示显示某个方法过载吗?

Mik*_*ike 10 c# intellisense overloading visual-studio

我有两种相互重载的方法

public class Car
{
   public int GetPrice(string vinNumber)
   {
      string make = Database.GetMake(vinNumber);  // expensive operation
      string model = Database.GetModel(vinNumber);   // expensive operation
      int year = Database.GetYear(vinNumber);   // expensive operation

      return this.GetPrice(make, model, year);
   }

   public int GetPrice(string make, string model, int year)
   {
      // Calculate value and return
   }
}
Run Code Online (Sandbox Code Playgroud)

在我的示例中,GetPrice(make,model,year)重载执行起来很便宜,但GetPrice(vinNumber)方法很昂贵.问题是昂贵的方法具有最少的参数,它首先出现在C#intellisense中.

这两种方法都是有效的,但我想鼓励人们称之为便宜的方法.但是在选择要调用的方法之前,人们往往不会查看Intellisense中的所有重载,并且在我公司的代码库中经常调用昂贵的重载.

有没有办法告诉Visual Studio为特定方法提供"intellisense优先级",以便它首先显示?

Gra*_*ton 1

不这么认为。

除非你编写一个智能感知插件(如Resharper)并劫持默认智能感知并创建一个程序供用户分配优先级。