【Resharper】C# “Simplify conditional ternary expression”
#事故现场:
对某个对象做空值检测的时候,结合三元运算符给某变量赋值的时候,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”的更多相关文章
- 【概率论】4-7:条件期望(Conditional Expectation)
title: [概率论]4-7:条件期望(Conditional Expectation) categories: - Mathematic - Probability keywords: - Exp ...
- 【概率论】3-6:条件分布(Conditional Distributions Part I)
title: [概率论]3-6:条件分布(Conditional Distributions Part I) categories: Mathematic Probability keywords: ...
- 【概率论】3-6:条件分布(Conditional Distributions Part II)
title: [概率论]3-6:条件分布(Conditional Distributions Part II) categories: Mathematic Probability keywords: ...
- 【概率论】2-1:条件概率(Conditional Probability)
title: [概率论]2-1:条件概率(Conditional Probability) categories: Mathematic Probability keywords: Condition ...
- 【LeetCode】71. Simplify Path 解题报告(Python)
[LeetCode]71. Simplify Path 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- Spring生态研习【二】:SpEL(Spring Expression Language)
1. SpEL功能简介 它是spring生态里面的一个功能强大的描述语言,支在在运行期间对象图里面的数据查询和数据操作.语法和标准的EL一样,但是支持一些额外的功能特性,最显著的就是方法调用以及基本字 ...
- 【LeetCode】71. Simplify Path
Simplify Path Given an absolute path for a file (Unix-style), simplify it. For example,path = " ...
- 【leetcode】1106. Parsing A Boolean Expression
题目如下: Return the result of evaluating a given boolean expression, represented as a string. An expres ...
- 【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 ...
随机推荐
- MySQL数据库~~~~ 完整性约束
1. not null 与 default not null : 不可空 default : 默认值 例: create table t1(id int not null default 2); 2. ...
- FS-Cache 调研
最近需要使用到 FSCache,今天调研一下FS-Cache,主要记录一些索引,方便以后查阅: RedHat 文档:https://access.redhat.com/documentation/en ...
- IDEA 工具自动生成JavaBean类
1.先安装GsonFormat插件:File-->Setting-->Plugins-->GsonFormat-->OK 2.new 一个新的Class空文件,然后 Alt+I ...
- Cocos2d-x 点击菜单按键居中放大(无需修改底层代码)
建议转至该处阅读 https://www.zybuluo.com/tangyikejun/note/21953 配置环境:win7+Cocos2d-x.2.0.3+VS2012 目标读者:已经了解Co ...
- 基于django的个人博客网站建立(四)
基于django的个人博客网站建立(四) 前言 网站效果可点击这里访问 今天主要添加了留言与评论在后台的管理和主页文章的分页显示,文章类别的具体展示以及之前预留链接的补充 主要内容 其实今天的内容和前 ...
- 千万级数据迁移工具DataX实践和geom类型扩展
## DataX快速入门参考 > 官方https://github.com/alibaba/DataX/blob/master/userGuid.md ## 环境要求 > Linux JD ...
- springmvc+mybatis需要的jar包与详解
https://www.cnblogs.com/luohengstudy/p/7772109.html
- C++ std::forward_list 基本用法
#include <iostream> #include <string> #include <forward_list> using namespace std; ...
- vuex——action,mutation,getters的调用
一.子模块调用根模块的方法 mutation调用 context.commit('clearloginInfo',{key_root:data},{root:true}); action调用 co ...
- [译]Vulkan教程(02)概况
[译]Vulkan教程(02)概况 这是我翻译(https://vulkan-tutorial.com)上的Vulkan教程的第2篇. This chapter will start off with ...