开发者

C#: How to find references to equals operator for a particular class in Visual Studio

开发者 https://www.devze.com 2023-04-04 16:54 出处:网络
I would like to override .Equals a开发者_如何学Gond the == operator for a class. I need to check whether there are any equality comparisons in use anywhere for that class at the moment. How would I do

I would like to override .Equals a开发者_如何学Gond the == operator for a class. I need to check whether there are any equality comparisons in use anywhere for that class at the moment. How would I do this?


In both cases, I would add the overload/override, and then use "Find Usages" (in Resharper), or "View Call Hierarchy" (Visual Studio native). If anything shows up, it will be a change.

Another approach (if neither is available) is to (just while doing this) add [Obsolete] to the override/overload methods you add - then any code that starts using them (i.e. has a change to behaviour) will show up as a warning.

Caveat: if the override (Equals) is part of an inheritance chain that already overrides Equals, note that code referencing the base-class will not appear in any of the above. This includes code using object.


I think you can do this by using Resharper. Resharper has a 'find usages' function which is quite powerfull.

You could override the Equals method in the class, right click on it, and select find usages advanced if you have R# installed.

Then, you'll get a list of places where that method is used.

0

精彩评论

暂无评论...
验证码 换一张
取 消