通过ReSharper的使代码的代码建议的可读性? [英] Code suggestions by Resharper making code less readable?

查看:92
本文介绍了通过ReSharper的使代码的代码建议的可读性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然试图让所有的绿色,我被ReSharper的以下建议

While trying to get to all green, i got the following suggestion by Resharper.

原始代码:

    static public string ToNonNullString(this XmlAttribute attr)
    {
        if (attr != null)
            return attr.Value;
        else
            return string.Empty;
    }



建议:去除多余的'其他'导致以下内容:

Suggestion: remove redundant 'else' resulting in following:

    static public string ToNonNullString(this XmlAttribute attr)
    {
        if (attr != null)
            return attr.Value;
        return string.Empty;
    }



对于我来说,建议的版本似乎比原来少了可读性。是否ReSharper的建议反映良好维护的代码定义?

To me, the suggested version seems less readable than the original. Does Resharper suggestion reflect the definition of good maintainable code?

推荐答案

从技术上ReSharper的是在正确的其他是不必要的,我。更喜欢前者,虽然作为其意图是比较明显的。

Technically Resharper is correct in that the "else" is unnecessary, I prefer the former version though as the intent is more obvious.

话虽如此,我宁愿一起去:

Having said that, I'd rather go with:

return attr != null ? attr.Value : string.Empty;

这篇关于通过ReSharper的使代码的代码建议的可读性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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