code-analysis

CA2000 error with 'using' statement. How to make this valid?

The following code is giving me this code analysis error CA2000 : Microsoft.Reliability : In method 'SessionSummary.SessionSummary_Load(object, EventArgs)', call System.IDisposable.Dispose on object 'entities' before all references to it are out of scope. I am using a 'using' statement, so I am surprised on this: private v...

Visual Studio Code analysis - Creating a new rule to count number of lines in methods

UPDATE I reflected Microsoft.Cci.dll and build my rule. It works fine. However, I am facing some problem which I put here with all the details. Source code is here. I didn't want to increase the length of this question by putting all the details. I am trying to write a code analysis rule which would raise warnings for methods having m...

How can I walk the method call to an Action, Func, or Delegate in introspector for a custom rule?

I'm writing a custom rule to verify the constructor of any control type calls initialize component. But when I hit these 2 edge cases: public Form1(int? testInt,bool testBool,bool testBool2) : this(false) { Action init = ( ) => InitializeComponent( ); init(); } public Form1(int? testInt, bool testBoo...

Can the new phoenix code analysis engine in vs2010 analyze source level or catch preprocessor calls?

I'm hoping there is someway built into VS2010 to have custom rules involving preprocessor usage, and source-level style/member ordering. Does it do source level, or catch preprocessor calls? ...

How do I get a breakup of my Lines Of Code?

Is there a tool that calculates various LOC statistics? It would have to support popular languages like C++, C#, Python, PHP, JavaScript, ActionScript, etc and interpret code accordingly. An example of the statistics I'm looking for: 350 Physical lines of code -- including braces 200 Logical lines of code -- actual code 190 Comment li...

Is there a clean way to read the config file during a custom rule (code analysis/Tfs check-in policy)?

I'm thinking of trying the following ideas: System.IO Package.GetGlobalService(typeof(EnvDTE.DTE)) public override Microsoft.FxCop.Sdk.ProblemCollection Check(Microsoft.FxCop.Sdk.Resource resource), while blocking on the thread that does Check(TypeNode type) until the resource reading completes. Anyone know if any of these will be re...

How to check if Thread code runs in try-catch block

I would like to validate our code and check if every Thread that we execute runs in try catch block. A valid sample: Thread loadDataThread = new Thread(new ThreadStart(LoadData)); public void LoadData() { try {/*do something*/} catch(Exception ex) { /*Handle exception*/ } } Not valid sample: Thread loadDataThread = new Thread(...

Extending homework testing platform to include code analysis (C/C++)

I'm maintaining/developing a platform for homework testing. It's mostly automatic. What I need to add now is code analysis. I need to check the code for specific constructs. For example: Does the file main.cpp contain a class named user with a const method get_name()? Is there some tool out there that would allow me to do suc...

How to identify what state variables are read/written in a given method in C#

What is the simplest way to identify if a given method is reading or writing a member variable or property? I am writing a tool to assist in an RPC system, in which access to remote objects is expensive. Being able to detect if a given object is not used in a method could allow us to avoid serializing its state. Doing it on source code ...

How to change the language of the Code Analysis help in Visual Studio 2010?

Hi there, I have a small issue with the Code Analysis in Visual Studio 2010. I'm running an English version of Windows 7 with Visual Studio 2010 Premium (English version) and Code Analysis. The region, location, number format etc in Windows 7 are set to Switzerland (German). If I use Code Analysis the messages are displayed in English....

Get methods, comments and classes from source code in java?

I'd like to somehow create some kind of class that can read a source code file(ie java) and from that extract the method names, the method source-code, the methods description comment and such. Is this possible in any simple way? I'd also like to avoid complicated parsers and such. Is regexp any good for this? Programming language = ja...

Code contracts problem

Consider the following code : public class RandomClass { private readonly string randomString; public RandomClass(string randomParameter) { Contract.Requires(randomParameter != null); Contract.Ensures(this.randomString != null); this.randomString = randomParameter; } public string R...

XML code documentation checking using Visual Studio 2010 Code Analysis

I use Visual Studio 2010 Premium Code Analysis (CA) capabilities and force them at every compile with my projects while also showing warnings as errors, so I keep my code nice and well... better. But. Since this CA is very nice and all I wouldn't want to use StyleCop as well. Because StyleCop gives me code style specification that CA d...

Tool for source code analysis?

Source code analysis and exploration tools for C and C++ seem to be sorely lacking. Are there any tools which I can use to gather information about C and/or C++ source files? cscope does part of what I would need, Doxygen looks closer. At a minimum list of all function, callers, callees, variable references etc. Perhaps Doxygen's xml ...

Howto overcome Unit Test Regression Problems...?

Hi, I was looking for some kind of a solution for software development teams which spend too much time handling unit test regression problems (about 30% of the time in my case!!!), i.e., dealing with unit tests which fails on a day to day basis. Following is one solution I'm familiar with, which analyzes which of the latest code change...

visual studio code analysis/metrics tools

Hi, I just downloaded a trial version of NDepend. What I'm looking for is a tool that helps in standardization of code. Not only in style of braces, spaces, naming conventions, etc, but also in cohesion & complexity. Is anybody using it that can tell me if I can integrate cohesion & complexity into the build errors (in example, if comp...

Scheme Code Analysis for Space vs. Time

I'm working my way through the online MIT lectures for the classic 6.001 course: The Structure and Interpretation of Computer Programs. I'm trying to gain an understanding of analyzing code complexity in terms of memory usage vs. execution time. In the first few lectures, they present a solution in Scheme for the Fibonacci Series. ...

The Cost of SQRT in C

How do you determine what the cycle cost is for a given C library function? Specifically, how expensive is it to call sqrt()? I should clarify here, I'm just looking for a general idea of the cost associated with calling certain C library functions. I'm assuming that professional C programmers just have a basic idea of function cost f...

Visual Studio 2010 Code Analysis - Run on Solution

Hello, I would like to manually run code analysis for an entire solution, not on building the project, and not using FXCop, if possible. I did enable CA on build but it really, really slowed down the build process, and we can't have that. But it seems weird to me that code analysis can only be run per project manually through the menu...

How can I mark a CA [SuppressMessage] as "blessed"?

Try as I might to keep [SuppressMessage]s to a minimum in the codebase, new ones continue to get introduced. I would like some way to say in the code "I've reviewed this [SuppressMessage] and it is 'acceptable'". One thought was to create my own My.CodeAnalysis.SuppressMessageAttribute class which inherits from System.Diagnostics.CodeA...