resharper

LINQ: Not Any vs All Don't

懵懂的女人 提交于 2019-11-26 05:59:37
问题 Often I want to check if a provided value matches one in a list (e.g. when validating): if (!acceptedValues.Any(v => v == someValue)) { // exception logic } Recently, I\'ve noticed ReSharper asking me to simplify these queries to: if (acceptedValues.All(v => v != someValue)) { // exception logic } Obviously, this is logically identical, perhaps slightly more readable (if you\'ve done a lot of mathematics), my question is: does this result in a performance hit? It feels like it should (i.e.

Why does ReSharper want to use 'var' for everything?

岁酱吖の 提交于 2019-11-26 04:38:42
问题 I\'ve just started using ReSharper with Visual Studio (after the many recommendations on SO). To try it out I opened up a recent ASP.NET MVC project. One of the first and most frequent things I\'ve noticed it suggesting is to change most/all my explicit declarations to var instead. For example: //From This: MyObject foo = DB.MyObjects.SingleOrDefault(w => w.Id == 1); //To This: var foo = DB.MyObjects.SingleOrDefault(w => w.Id == 1); and so on, even with simple types such as int , bool , etc.

What does CultureInfo.InvariantCulture mean?

我们两清 提交于 2019-11-26 03:37:06
问题 I have a string of text like so: var foo = \"FooBar\"; I want to declare a second string called bar and make this equal to first and fourth character of my first foo , so I do this like so: var bar = foo[0].ToString() + foo[3].ToString(); This works as expected, but ReSharper is advising me to put Culture.InvariantCulture inside my brackets, so this line ends up like so: var bar = foo[0].ToString(CultureInfo.InvariantCulture) + foo[3].ToString(CultureInfo.InvariantCulture); What does this

Access to Modified Closure (2)

梦想与她 提交于 2019-11-26 03:29:46
问题 This is an extension of question from Access to Modified Closure. I just want to verify if the following is actually safe enough for production use. List<string> lists = new List<string>(); //Code to retrieve lists from DB foreach (string list in lists) { Button btn = new Button(); btn.Click += new EventHandler(delegate { MessageBox.Show(list); }); } I only run through the above once per startup. For now it seems to work alright. As Jon has mentioned about counterintuitive result in some case

What is the difference between a regular string and a verbatim string?

怎甘沉沦 提交于 2019-11-26 03:15:20
问题 I have a trial version of Resharper and it always suggests that I switch regular strings to verbatim strings. What is the difference? 回答1: A verbatim string is one that does not need to be escaped, like a filename: string myFileName = "C:\\myfolder\\myfile.txt"; would be string myFileName = @"C:\myfolder\myfile.txt"; The @ symbol means to read that string literally, and don't interpret control characters otherwise. 回答2: This is covered in section 2.4.4.5 of the C# specification: 2.4.4.5

Method can be made static, but should it?

耗尽温柔 提交于 2019-11-26 01:28:58
问题 Resharper likes to point out multiple functions per asp.net page that could be made static. Does it help me if I do make them static? Should I make them static and move them to a utility class? 回答1: Static methods versus Instance methods 10.2.5 Static and instance members of the C# Language Specification explains the difference. Generally, static methods can provide a very small performance enhancement over instance methods, but only in somewhat extreme situations (see this answer for some

Handling warning for possible multiple enumeration of IEnumerable

末鹿安然 提交于 2019-11-26 01:12:23
问题 In my code in need to use an IEnumerable<> several times thus get the Resharper error of \"Possible multiple enumeration of IEnumerable \". Sample code: public List<object> Foo(IEnumerable<object> objects) { if (objects == null || !objects.Any()) throw new ArgumentException(); var firstObject = objects.First(); var list = DoSomeThing(firstObject); var secondList = DoSomeThingElse(objects); list.AddRange(secondList); return list; } I can change the objects parameter to be List and then avoid

Invert “if” statement to reduce nesting

て烟熏妆下的殇ゞ 提交于 2019-11-26 01:10:32
问题 When I ran ReSharper on my code, for example: if (some condition) { Some code... } ReSharper gave me the above warning (Invert \"if\" statement to reduce nesting), and suggested the following correction: if (!some condition) return; Some code... I would like to understand why that\'s better. I always thought that using \"return\" in the middle of a method problematic, somewhat like \"goto\". 回答1: A return in the middle of the method is not necessarily bad. It might be better to return

Access to Modified Closure

删除回忆录丶 提交于 2019-11-25 23:18:11
问题 string [] files = new string[2]; files[0] = \"ThinkFarAhead.Example.Settings.Configuration_Local.xml\"; files[1] = \"ThinkFarAhead.Example.Settings.Configuration_Global.xml\"; //Resharper complains this is an \"access to modified closure\" for (int i = 0; i < files.Length; i++ ) { // Resharper disable AccessToModifiedClosure if(Array.Exists(Assembly.GetExecutingAssembly().GetManifestResourceNames(), delegate(string name) { return name.Equals(files[i]); })) return Assembly.GetExecutingAssembly

开发中常用的一些神器推荐

筅森魡賤 提交于 2019-11-25 22:57:09
目录: Resharper TortoiseGit SQLDiff tinypng.com 1、Resharper 简介 是一款Visual Studio 插件,能深度代码分析,智能代码协助,实时错误代码高亮显示,解决方案范围内代码分析,快速代码更正,一步完成代码格式化和清理,业界领先的自动代码重构,高级的集成单元测试方案,和强大的解决方案内导航和搜索。 支持的语言: ·C#:ReSharper 2019.2完全支持高达C#8.0的所有C#版本。 ·VB.NET、 TypeScript、C ++。 ·JavaScript : ReSharper完全支持JavaScript 直到ECMAScript 2016,包括实验性功能,例如异步/等待,指数运算符以及对象文字/解构中的休息/传播。 jQuery和JSX语法也受支持。 ·CSS ReSharper支持CSS直至4.0版本。 编码效率至少提高30%以上。缺点:占内存。 Resharper 类似的插件aiXcoder: aiXcoder支持的编程语言有 Java,Python,C++,Php,JavaScript,TypeScript,Go。支持的编辑器有IntelliJ IDEA,Eclipse,PyCharm,Android Studio,PhpStorm,WebStorm、Clion,sublime、Visual