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.
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?
with best regards, emi
all you need to do is hold Ctrl and Shift and press F or click on Edit -> Find and Replace -> Find In Files. This will open up a dialog box that will let you enter your search criteria. Simply hit the Find All button and you will see a list of results returned to you that match your criteria.
Ctrl + Shift + F – Find in Solution Sometimes you want to search across your entire solution. You can double-click each item in the “Find Results” window to navigate to that instance of the search term you searched for.
Visual Studio 17.2 Preview 3 introduces a brand-new All-In-One search experience that merges the existing VS Search (Ctrl + Q) and Go To (Ctrl + T) to allow you to search both your code and Visual Studio features quicker and easier than ever, all in the same place.
Find in Files (Ctrl+Shift+F): A more robust option, Find in Files is better for searching entire projects or solutions. Unlike Quick Find, Find in Files can list search results in the Find Results window and has additional options to specify which file extensions to search.
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.
You could always use a find / replace on "==". You can use the filters to determine what / where you want to search or just use the Entire Solution.
You might be able to use .NET Reflector or maybe the Visual Studio call hierarchy window to look for calls to the operator== method of the IPAdress class. I don't know if this is possible, just throwing out an idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With