我有两个互相重载的方法
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
}
}
在我的示例中,GetPrice(make, model,year) 重载的执行成本很低,但 GetPrice(vinNumber) 方法的执行成本很高。问题是昂贵的方法具有最少的参数,并且它首先出现在 C# 智能感知中。
这两种方法都是有效的,但我想鼓励人们调用便宜的方法。但人们在选择要调用的方法之前往往不会仔细检查 Intellisense 中的所有重载,而昂贵的方法在我公司的代码库中被调用得过于频繁。
有没有办法告诉 Visual Studio 为特定方法提供“智能感知优先级”,以便它首先显示?
- XML 注释中的摘要标签显示在 Intellisense 中。
-
您可以使用 Obsolete 标记来装饰该方法,这也会根据设置生成警告或错误。
[System.Obsolete("use GetPrice(make, model, year)")]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)