resharper 3.0 中关于 method can be made static
转
In version 2.5 ReSharper go lots of new code warning highlights. One of the most annoying is certainly “This method could be made static”. First I didn’t even figure it out why it marks some methods like that and I quickly disabled the warning.
When fiddling with SubText code I was running FxCop tests and i spotted similar warning. But FxCop also gives explanations about it’s warnings:
"Methods which do not access instance data or call instance methods can be marked as static (Shared in VB). After doing so, the compiler will emit non-virtual call sites to these members which will prevent a check at runtime for each call that insures the current object pointer is non-null. This can result in a measurable performance gain for performance-sensitive code. In some cases,the failure to access the current object instance represents a correctness issue."
Good enough for me! It’s back on! I even respect the warning and make most affected methods static. But there are still one problem. I’m not sure that it’s correct to put this warning on event handlers. And I’m not the only one.
Let’s wait and see what happens in 2.5.1!
就是说Static方法因为不需要检查是否指针为空,性能会有很大提升,所以有如上建议。
浙公网安备 33010602011771号