code-analysis

Creating a custom rule in FxCop

早过忘川 提交于 2019-12-17 12:37:19
问题 I want to create extra rules in FXCop. Custom Rules to help ensure specific best practices like checking against inline sql. I'm really looking for good resources and examples. Thanks! 回答1: This tutorial seems really comprehensive. 回答2: The tutorial above is pretty good. I knocked together a sample VS project that also might be useful, since I couldn't find any example projects http://www.doogal.co.uk/files/FxCopRules.zip 回答3: You can also use the commercial tool NDepend to write your custom

Collection<T> versus List<T> what should you use on your interfaces?

别说谁变了你拦得住时间么 提交于 2019-12-17 02:39:10
问题 The code looks like below: namespace Test { public interface IMyClass { List<IMyClass> GetList(); } public class MyClass : IMyClass { public List<IMyClass> GetList() { return new List<IMyClass>(); } } } When I Run Code Analysis i get the following recommendation. Warning 3 CA1002 : Microsoft.Design : Change 'List' in 'IMyClass.GetList()' to use Collection, ReadOnlyCollection or KeyedCollection How should I fix this and what is good practice here? 回答1: To answer the "why" part of the question

Visual Studio GlobalSuppression.cs file and UTF-16

China☆狼群 提交于 2019-12-14 03:44:03
问题 It seems that Visual Studio 2015 saves the GlobalSuppression.cs file using a UTF-16 encoding. This is annoying when using SVN as it perceives that a UTF-16 file is a binary file. Questions: Using Visual Studio, is it possible to save GlobalSuppression.cs with a UTF-8 encoding? Alternatively, can someone provide a location where I can find the template that this file is based on (if one exists)? Note that I can't find a template in Common7\IDE\ItemTemplates . 回答1: To change the encoding of the

Suppress CA1062 with fluent validation

ε祈祈猫儿з 提交于 2019-12-14 00:58:05
问题 I have a fluent, extensible validation helper like: Assert.That(aParameter).IsNotNull(); It is extensible because the That method is actually generic (That<T>) and uses implicit typing to return a generic IAssertCondition<T> object. IsNotNull is actually an extension method. Anyway, the problem using this approach to validate the parameters passed into a method is that I get CA1062 warnings instructing me to validate the arguments before using them which, of course, I am already doing. I read

Code analysis, Lost between CA1709 and CA1704

[亡魂溺海] 提交于 2019-12-13 19:25:25
问题 Because of these two KB articles, I am confused: CA1704: Identifiers should be spelled correctly CA1709: Identifiers should be cased correctly I have a property named ICD9 . My code analysis says that I have to change it to Icd That sounds reasonable to me. I go and change it to Icd9 (I am not sure why it's suggesting Icd not Icd9 ) and I get a different warning The KB says if my acronym is three-letter long I should use Pascal casing. Isn't Icd9 Pascal cased? I feel that 9 has causing the

Algorithm running time

北慕城南 提交于 2019-12-13 09:55:08
问题 What would the running time be? I got O(n^2) `cin >> n; min = 2*n; max = (n+3)*10; for(int i=0; i<1000; i++) for(int j =0; j<n; j++) for(int k = min; k< max;k++) p = f+c+m ` 回答1: No matter what outer loop runs 1000 times..so the complexity ~ O(n^2) . [innermost runs 10n+30-2n = 8n+30 times and loop with variable j runs n times..] 回答2: The number of times p is computed is: 1000 * n * (max - min) = 1000 * n * ((n + 3)*10 - 2*n) = 1000 * n * (10*n + 30 - 2*n) = 1000 * n * (8*n + 30) = 8000 * n^2

Time complexity with conditional statements

雨燕双飞 提交于 2019-12-13 05:49:29
问题 How does one calculate the time complexity with conditional statements that may or may not lead to higher oder results? For example: for(int i = 0; i < n; i++){ //an elementary operation for(int j = 0; j < n; j++){ //another elementary operation if (i == j){ for(int k = 0; k < n; k++){ //yet another elementary operation } } else { //elementary operation } } } And what if the contents in the if-else condition were reversed? 回答1: Your code takes O(n^2). First two loops take O(n^2) operations.

Code Analysis Not Available in This Edition of the Compiler

纵然是瞬间 提交于 2019-12-13 04:42:02
问题 I'm trying to run code analysis for the first time on my native C++ application. I'm developing using Visual Studio 2013 Ultimate and compiling using the Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013), which is the latest (I believe) compiler from MS for C++11. When trying to run Code Analysis I receive the following warning: warning D9040: ignoring option '/analyze'; Code Analysis warnings are not available in this edition of the compiler So I'm wondering if it's because I'm using this new

Code analysis CA0001 error for project using NSubstitute

半腔热情 提交于 2019-12-13 03:38:25
问题 I have a (.NET 4) test project which references (the .NET 4) NSubstitute.dll. When I run CodeAnalysis against the project I get a number of CA0001 errors: Running Code Analysis... MSBUILD : error : CA0001 : The following error was encountered while reading module 'NSubstitute': Could not resolve type reference: [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]System.Runtime.CompilerServices.ExtensionAttribute. MSBUILD : error : CA0001 : Rule=Microsoft

Why is warning CA2214 not resolved when a sealed override method is generic?

馋奶兔 提交于 2019-12-13 01:27:55
问题 Given the following class heirarchy: class Base { protected virtual void Do(int value) { } } class Derived1 : Base { sealed protected override void Do(int value) { base.Do(value); } } class Derived2 : Derived1 { public Derived2() { Do(999); } } ... the code analysis warning CA2214 is resolved by simply adding the sealed keyword to Derived1.Do() . So far, so good. Now let's make Do() generic: class Base { protected virtual void Do<T>(T value) { } } class Derived1 : Base { sealed protected