#事故现场:

  对某个对象做空值检测的时候,结合三元运算符给某变量赋值的时候,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. iOS 中使用 webSocket

    iOS 中使用 webSocket 是服务器和app之间的一种通信方式 webSocket 实现了服务端推机制(主动向客户端发送消息).新的 web 浏览器全都支持 WebSocket,这使得它的使用 ...

  2. Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

    使用Qt写了个窗口,运行报错,无法正常运行python程序,获得的报错信息如下: Process finished with exit code 139 (interrupted by signal ...

  3. redis scan命令使用

      以前的项目中有用到redis的keys命令来获取某些key,知道看了这篇文章 https://mp.weixin.qq.com/s/SGOyGGfA6GOzxwD5S91hLw.安全起见,这次打算 ...

  4. leetcode题解:两数之和

    给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同样的元 ...

  5. Python 变量与运算符

    变量 基本概念: 1. 变量,名字,数据的唯一标识2.变量命名: 字母.数字.下划线: 不能以数字开头: 区分大小写: 不能使用保留字和关键字: 命名要有意义:(多个单词时,推荐使用下划线连接) 3. ...

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

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

  7. kubernetes haproxy+keepalive实现master集群高可用

    前言 master的HA,实际是apiserver的HA.Master的其他组件controller-manager.scheduler都是可以通过etcd做选举(--leader-elect),而A ...

  8. 多线程十 Timer

    定时/计算在java中主要使用的是Timer对象,他的内部依然是采用多线程方式进行处理 它有四个构造方法 方法名 作用 Timer() 空参 Timer(String name) 指定名字 Timer ...

  9. ASP.NET Core 3.0 gRPC 配置使用HTTP

    前言 gRPC是基于http/2,是同时支持https和http协议的,我们在gRPC实际使用中,在内网通讯场景下,更多的是走http协议,达到更高的效率,下面介绍如何在 .NET Core 3.0 ...

  10. ThinkPHP中框架查询

    1.查询多条数据          1.1静态调用all方法或者select方法 // 获取所有数据 all 和 select $list = User::all(); // 根据主键获取多个数据al ...