关于==的警告,用于引用(Visual Studio或ReSharper) [英] Warning on == used on references (Visual Studio or ReSharper)

查看:133
本文介绍了关于==的警告,用于引用(Visual Studio或ReSharper)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据



如果您感兴趣的话,这里是扩展在市场中。

这是源代码



目前,它检查对象是否具有对运算符 ==和!=的替代。愿意捐款的人绝对值得欢迎。


According to the documentation of the == operator in MSDN,

For reference types other than string, == returns true if its two operands refer to the same object.

But, to be honest, I never check if two references are the same with ==.
I prefer using ReferenceEquals(obj1, obj2) and so do the default override of the Equals function.

Therefore, in my projects, when the == operator is used on other types than string, equals to a bug.

Is there a way to trigger a warning/error through Visual Studio or ReSharper when == is used on references (apart from string)?

解决方案

As suggested, I created an extension to do that.

If you're interested, here is the link to the extension in the marketplace.
And here is the link to the source code.

At the moment it does not check if the object has an override for the operators "==" and "!=". Whoever wants to contribute is more than welcome to do so.

这篇关于关于==的警告,用于引用(Visual Studio或ReSharper)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆