NDepend customize rule: Instance fields should be prefixed with a 'm_'

NDepend is a tool that offers a wide range of features to let developers analyze a .NET code base. It comes with about 200 built in rules. But there are a few default rules that do not fit “my rules”. This blog post shows how to customize one and even more important why. Instance fields should be prefixed with a 'm_' I prefix instance fields with a ‘_’ not with ‘m_’ so I need to customize the default rule: warnif count > 0 from f in Application.Fields where !f.NameLike (@"^_") && !f.IsStatic && !f.IsLiteral && !f.IsGeneratedByCompiler && !f.IsSpecialName && !f.IsEventDelegateObject select new { f, f.SizeOfInst }

Validating Code Quality with NDepend

Patrick Smacchia’s NDepend is a great tool to improve code quality and should be run quite regularly. It can be run as a strand alone GUI tool, from inside Visual Studio and as part of your build process. I’ll use the tool over the next few weeks to analyze and improve the quality of one of my personal code bases. I’ll try to share my experiences beside tips and tricks as well as giving feedback to Patrick. Code Rules an Queries At first I’d like to highlight one of the most powerful features: Code Rules an Queries. This lets query your code base over LINQ queries thanks to CQLinq. There are about 200 default rules. The power really evolves as you start customizing these and further on start writing your own rules. Here is an example: from m in Application.Methods where m.NbLinesOfCode > 30 && m.IsPublic select m And a screenshot of the Editor: Wishlist As X-Mas is soon I’ll write down a few things I would have expected or that would improve the tooling experience. Tab a selection in “Query and Rules Edit” Currently a tab on a selected range removes the range. Tabbing helps me to keep code readable.

Re: How to change the default browser in Visual Studio programmatically

I’d really like to thank Scott Hanselman for digging into the nitty gritty details of how to change the Visual Studio Default Browser. But… let me cite one of the comments: “Should adding browser options to Visual Studio be <sarcasm>this easy</sarcasm>?” I hope we all agree on: Go fix this! As I have not found my way to powershell (yet) and I want to have VS Integration (as Scott finalizes his post) too: Here comes the macro version…Sub SetInternetExplorerAsDefaultBrowser() Dim FilePath As String = _ Path.Combine( _ Environment.GetFolderPath( _ Environment.SpecialFolder.UserProfile), _ "AppData\Local\Microsoft\VisualStudio\10.0\browsers.xml") Dim xml As String = "<?xml version=""1.0""?>" & vbCrLf & _ "<BrowserInfo>" & _ "<Browser>" & _ "<Name>Internet Explorer</Name>" & _ "<Path>""C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE""</Path>" & _ "<Resolution>3</Resolution>" & _ "<IsDefault>True</IsDefault>" & _ "<DDE><Service>IExplore</Service>" & _ "<TopicOpenURL>WWW_OpenURL</TopicOpenURL>" & _ "<ItemOpenURL>""%s"",,0xffffffff,3,,,,</ItemOpenURL>" & _ "<TopicActivate>WWW_Activate</TopicActivate>" & _ "<ItemActivate>0xffffffff,0</ItemActivate>" & _ "</DDE>" & _ "</Browser>" & _ "</BrowserInfo>" If (File.Exists(FilePath)) Then File.Delete(FilePath) End If Using sw As New StreamWriter(FilePath) sw.Write(xml) End Using Dim ConfigFile As New FileInfo(FilePath) Using key As RegistryKey = _ Registry.CurrentUser.OpenSubKey( _ "Software\" & _ "Microsoft\" & _ "VisualStudio\" & _ "10.0\" & _ "WebBrowser\" & _ "ConfigTimestamp", _ True) key.SetValue( _ "LastConfigurationTimestamp", _ DateTime.Now.ToUniversalTime().ToFileTime(), _ RegistryValueKind.QWord) key.SetValue( _ "CacheFileDateLastMod", _ ConfigFile.LastWriteTimeUtc.ToFileTime(), _ RegistryValueKind.QWord) key.SetValue( _ "CacheFileSizeBytes", _ ConfigFile.Length, _ RegistryValueKind.DWord) End Using End Sub