在Visual Studio中查找所有与==进行比较的情况 [英] find all occurrences of comparison with == in visual studio
问题描述
我犯了一个错误,即使用==来比较IP地址,而不是使用C#中IPAddress类的equals()方法,这将导致比较引用而不是值。
因为我目前正在使用的解决方案对于一个人的项目非常大(> 100.000行源代码),所以我非常确定我的代码中仍然有一些错误的语句。
I made the mistake of using == for comparing IP addresses instead of using the equals() method of the IPAddress class in C#, which will result in the comparison of references instead of values. Since the solution I am currently working on is very large for a one-man project (> 100.000 lines of source code), I am very sure that I still have some of these wrong statements in my code.
是否有可能告诉Visual Studio为我查找特定类上所有==操作的出现,以便我可以查找并清理错误的比较?
Is there any possibility to tell Visual Studio to find all occurrences of == operations on a specific class for me, so that I can find and clean up the bugged comparisons?
最好的问候,emi
推荐答案
有点hack,但是您可以暂时将此类添加到您的项目中:
It's a bit of a hack but you can temporarily add this class to your project:
namespace System.Net
{
class IPAddress
{
[Obsolete]
public static bool operator ==(IPAddress a, IPAddress b) { return true; }
[Obsolete]
public static bool operator !=(IPAddress a, IPAddress b) { return true; }
}
}
编译并查找有关使用过时方法的警告:
Compile and look for warnings about using obsolete methods:
Warning 'IPAddress.operator ==(IPAddress, IPAddress)' is obsolete
固定代码后,删除类定义。
Once you have fixed the code, remove the class definition.
这篇关于在Visual Studio中查找所有与==进行比较的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!