#事故现场:

  对某个对象做空值检测的时候,结合三元运算符给某变量赋值的时候,R#提示:"Simplify conditional ternary expression" ;

  R#建议对该种写法进行简写优化;

#解决方案:

  我们可以按住 Alt+Enter ,接受R#的建议,则代码优化如下:

bool isFuzzySearch = context.Request["IsFuzzySearch"] != null && bool.Parse(context.Request["IsFuzzySearch"]);

  优化后的代码中,同样存在空值检测,只不过使用 != ,同时三元运算符改为了 && ,也就是说只有当 context.Request["IsFuzzySearch"] != null  为真的时候,才会执行 bool.Parse(context.Request["IsFuzzySearch"]),最终结果同样满足了业务逻辑;

  优化后的代码在语义上和优化前的代码是等价的,R#通常更喜欢更简洁的方式,特别是,条件中使用"true" 和"false",R#会认为其是冗余代码的标记;

#参考:

https://stackoverflow.com/questions/14621907/simplify-conditional-ternary-expression

——————————————————————————————————————————

【Resharper】C# “Simplify conditional ternary expression”的更多相关文章

  1. 【概率论】4-7:条件期望(Conditional Expectation)

    title: [概率论]4-7:条件期望(Conditional Expectation) categories: - Mathematic - Probability keywords: - Exp ...

  2. 【概率论】3-6:条件分布(Conditional Distributions Part I)

    title: [概率论]3-6:条件分布(Conditional Distributions Part I) categories: Mathematic Probability keywords: ...

  3. 【概率论】3-6:条件分布(Conditional Distributions Part II)

    title: [概率论]3-6:条件分布(Conditional Distributions Part II) categories: Mathematic Probability keywords: ...

  4. 【概率论】2-1:条件概率(Conditional Probability)

    title: [概率论]2-1:条件概率(Conditional Probability) categories: Mathematic Probability keywords: Condition ...

  5. 【LeetCode】71. Simplify Path 解题报告(Python)

    [LeetCode]71. Simplify Path 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  6. Spring生态研习【二】:SpEL(Spring Expression Language)

    1. SpEL功能简介 它是spring生态里面的一个功能强大的描述语言,支在在运行期间对象图里面的数据查询和数据操作.语法和标准的EL一样,但是支持一些额外的功能特性,最显著的就是方法调用以及基本字 ...

  7. 【LeetCode】71. Simplify Path

    Simplify Path Given an absolute path for a file (Unix-style), simplify it. For example,path = " ...

  8. 【leetcode】1106. Parsing A Boolean Expression

    题目如下: Return the result of evaluating a given boolean expression, represented as a string. An expres ...

  9. 【HTML】Advanced2:Conditional Comments

    1.try and figure out what is sensible for you to support. Are your web site visitors likely to be us ...

随机推荐

  1. 基于Moya、RxSwift和ObjectMapper优雅实现REST API请求

    在Android开发中有非常强大的 Retrofit 请求,结合RxJava可以非常方便实现 RESTful API 网络请求.在 iOS开发中也有非常强大的网络请求库 Moya ,Moya是一个基于 ...

  2. Android TeaPickerView数据级联选择器

    数据级联选择器.三级联动.二级联动.层级联动.多数据筛选.必藏 (Data Cascade Selector, Hierarchical Structure, Multiple Data Screen ...

  3. [20191127]表 full Hash Value的计算.txt

    [20191127]表 full Hash Value的计算.txt --//曾经做过表full Hash Value的计算,当时我是通过建立简单的schema以及表名的形式,使用hashcat破解o ...

  4. linux下安装make工具

    安装make工具 make工具依赖gcc ,automake,autoconf,libtool,make 这些安装包 可以一起安装 center os系统 运行如下命令yum install gcc ...

  5. C# 类库项目 无法创建 “资源字典” 文件

    1.接触WPF有两个月时间了,准备自己写一个样式库,在vs新建 类库项目后无法创建资源字典. 2.解决办法: 打开项目工程文件      (  project.csproj) 在 <Proper ...

  6. unittest框架之 BeautifulReport 模板报告生成的正确姿势

    使用unittest框架的自动化测试,报告一定很重要,目前介绍一个比较高大上的报告模板 BeautifulReport.如果首次使用的话需要安装 pip install beautifulreport ...

  7. 解决IDEA中的DashBoard 不显示端口号

    第一步:找到.idea目录下的workspace.xml文件 第二步:找到下图位置 并添加红色部分代码 添加代码如下: <option name="configurationTypes ...

  8. SpringBoot系列之日志框架使用教程

    目录 1.SpringBoot日志级别 1).日志级别简介 2).默认日志级别 3).配置日志级别 4).日志分组设置 2.SpringBoot日志格式设置 1).默认格式原理简介 2).默认日志格式 ...

  9. Python 从入门到进阶之路(二)

    之前的文章我们对 Python 语法有了一个简单的认识,接下来我们对 Python 中的 if while for 做一下介绍. 上图为 if 判断语句的流程,无论任何语言,都会涉及到判断问题,if ...

  10. PAT 1008 Elevator 数学

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...