code-analysis

Any way to avoid warning C6386, without disabling it or Code Analysis altogether

青春壹個敷衍的年華 提交于 2021-02-10 07:57:09
问题 Visual Studio 2019 started showing Code Analysis warnings as in-editor green squiggles by default. These may be extremely useful for students learning C programming, because they catch classical mistakes, such as off by one array accesses. Unfortunately false positives may completely ruin the learning experience and I fear that I will have to ask the students to disable the feature in order to avoid having them worry on non existing problems. This short snippet doesn't cause any warning:

What is the static analysis rule to warn about unused using statements?

落花浮王杯 提交于 2021-02-09 07:16:21
问题 Is there any FxCop or StyleCop that warns when there is an using statement that is no longer referenced by any object in the file? 回答1: You can enable the rule IDE0005 C# Using directive is unnecessary. in the category Style . 回答2: In addition to Udo's answer and this answer, I also needed to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses . So all in all: Set the Warning Level to 4 for code analyzers to fire. Set rules CS8019

What is the static analysis rule to warn about unused using statements?

强颜欢笑 提交于 2021-02-09 07:13:24
问题 Is there any FxCop or StyleCop that warns when there is an using statement that is no longer referenced by any object in the file? 回答1: You can enable the rule IDE0005 C# Using directive is unnecessary. in the category Style . 回答2: In addition to Udo's answer and this answer, I also needed to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses . So all in all: Set the Warning Level to 4 for code analyzers to fire. Set rules CS8019

What is the static analysis rule to warn about unused using statements?

时光毁灭记忆、已成空白 提交于 2021-02-09 07:13:22
问题 Is there any FxCop or StyleCop that warns when there is an using statement that is no longer referenced by any object in the file? 回答1: You can enable the rule IDE0005 C# Using directive is unnecessary. in the category Style . 回答2: In addition to Udo's answer and this answer, I also needed to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses . So all in all: Set the Warning Level to 4 for code analyzers to fire. Set rules CS8019

What is the static analysis rule to warn about unused using statements?

北城余情 提交于 2021-02-09 07:10:59
问题 Is there any FxCop or StyleCop that warns when there is an using statement that is no longer referenced by any object in the file? 回答1: You can enable the rule IDE0005 C# Using directive is unnecessary. in the category Style . 回答2: In addition to Udo's answer and this answer, I also needed to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses . So all in all: Set the Warning Level to 4 for code analyzers to fire. Set rules CS8019

How can I find previous usages of a variable using Roslyn?

本小妞迷上赌 提交于 2021-02-08 02:57:32
问题 I'm writing a Rosyln analyser/analyzer. It checks to ensure that a method is called before accessing another (potentially dangerous) method on a type. To show what I mean, here's some bad code that I want to analyse and fail on: private void myMethod() { var myThing = new MyThing(); myThing.Value = null; string value = myThing.GetValue(); // code blows up here as the internal value is null } Here's code that's OK because it calls a method that says whether it's null: private void myMethod() {

Timing C# code using Timer

我们两清 提交于 2021-01-28 08:01:22
问题 Even though it is good to check performance of code in terms of algorithmic analysis and Big-Oh! notation i wanted to see how much it takes for the code to execute in my PC. I had initialized a List to 9999count and removed even elements out from the them. Sadly the timespan to execute this seems to be 0:0:0 . Surprised by the result there must be something wrong in the way i time the execution. Could someone help me time the code correct? IList<int> source = new List<int>(100); for (int i =

Static code analysis not working for custom ruleset

本小妞迷上赌 提交于 2021-01-07 06:37:44
问题 We are trying to have our own custom ruleset which we can apply during build process. For this I've created custom rule and custom ruleset but analysis doesn't work however I've tested the rule using Debug--> Start External program and it produced correct xml Already placed rule dll and ruleset inside fxcop rule and ruleset folder Rule XML <?xml version="1.0" encoding="utf-8" ?> <Rules> <Rule TypeName="CustomRule" Category="Performance" CheckId="R001" > <Name>AvoidUsingVirtualMethods</Name>

Static code analysis not working for custom ruleset

痞子三分冷 提交于 2021-01-07 06:33:22
问题 We are trying to have our own custom ruleset which we can apply during build process. For this I've created custom rule and custom ruleset but analysis doesn't work however I've tested the rule using Debug--> Start External program and it produced correct xml Already placed rule dll and ruleset inside fxcop rule and ruleset folder Rule XML <?xml version="1.0" encoding="utf-8" ?> <Rules> <Rule TypeName="CustomRule" Category="Performance" CheckId="R001" > <Name>AvoidUsingVirtualMethods</Name>