Tuesday, May 27, 2008

Microsoft Source Analysis for C#

Microsoft announce the public release of a new developer tool -  Source Analysis for C#.

Inside Microsoft this tool's name is StyleCop and it enforces code style guidelines on the code we write

Source Analysis comes with a set of default rules analyzers covering approximately 200 best practice rules. These rules are full compatible with the default layout settings in Visual Studio 2005 and Visual Studio 2008.

Specifically, these rules cover the following, in no particular order:

  • Layout of elements, statements, expressions, and query clauses
  • Placement of curly brackets, parenthesis, square brackets, etc
  • Spacing around keywords and operator symbols
  • Line spacing
  • Placement of method parameters within method declarations or method calls
  • Standard ordering of elements within a class
  • Formatting of documentation within element headers and file headers
  • Naming of elements, fields and variables
  • Use of the built-in types
  • Use of access modifiers
  • Allowed contents of files
  • Debugging text

After installation, Source Analysis can be run from within the Visual Studio IDE. You can set this up to be run as a part of your build process as documented here. Since this is plugged in as a MsBuild project you can use it in as a part of Team Foundation Build process as well.

 

Running Source Analysis:

sca1

And the results are:

sca2

 

Download it from: http://code.msdn.microsoft.com/sourceanalysis

Read full details:http://blogs.msdn.com/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx

Tuesday, May 20, 2008

Search File System Using LINQ

Do you want to search a file or file type in the file system ? Nice way to do it is using LINQ.

var files = from file in new DirectoryInfo(@"D:\temp").GetFiles()
where file.Name == "MyFile.txt"
select file;


Or even search after specific file extension :



var files = from file in new DirectoryInfo(@"D:\temp").GetFiles()
where file.Extension == ".txt"
select file;


Enjoy,



Maor