.NET

Huge News! Get Windows 8 and Windows Phone Controls for FREE for the Duration of TechEd 2014

TechEd 2014 is on, and I’m envious that I’m not in attendance. However, Telerik, purveyor of controls for application development, are giving away licenses for their Windows 8 and Windows Phone control packs over the duration of TechEd. I’ve gone through the claim process, the licenses are equivalent to the one-year subscription options, and apparently can be renewed or upgraded. Not only that, but Telerik are working on components for the new universal apps, and have stated that these new components will be added free of charge to the accounts of any who get the free tools this week!

This is a fabulous offering for those on the fence over trying the tools, and very timely for me as I was planning to purchase a Windows 8 pack. I save some money now, and just might be renewing later – many thanks to Telerik for the freebie. The generosity is much appreciated so I can get started on Windows 8 application development.

Review: Effective C#, Second Edition

Effective C# - cover

Author: Bill Wagner
Publisher: Addison Wesley
Published: 2010
Pages: 328

This is the second edition of a book with the same title, written for C# 1. This book was written to C# 4. There is a companion book, More Effective C#, written to C# 3, and covering language features added following the original book’s publication.

This book contains fifty items, divided among six chapters. Some of the chapters are highly topical, covering closely related items. Other chapters, especially the last one, are broader and less-focused groupings.

The chapters are:

  1. C# Language Idioms
  2. .NET Resource Management
  3. Expressing Designs in C#
  4. Working with the Framework
  5. Dynamic Programming in C#
  6. Miscellaneous

Across the chapters, numerous less-understood language features are covered, including but not limited to:

  • boxing and unboxing
  • garbage collection
  • interfaces
  • delegates
  • dynamics
  • parallel programming
  • covariance & contravariance
  • optional parameters
  • query syntax versus loops
  • equality checking

Some of the topic areas I already had at least some understanding of, but many I did not. In both cases, I learned much, and consider myself improved for becoming aware of these language features. While not all, or even any, of these features are useful for every situation, it is good to know of these features so they can be used where appropriate, and correctly.

The bottom line: This book is not for beginners – it is not a tutorial, cookbook, or reference. It is a guide to making the best possible use of C# constructs. For intermediate or advanced programmers, it is a recommended read to understand intricacies of C# and .NET.

A console window lists NDepend's power tools

Review: NDepend v4

I’ve previously written about using NDepend, by Patrick Smacchia, to analyze code compiled for .NET and generate useful metrics and diagrams. That was last about version 2, as part of my .NET Tooling series. I am now on version 4, and thought it worth exploring some of the changes to the tool since then. I won’t go into the whats, whys, or hows about NDepend, which are well-covered in my previous post, but will focus on changes in the new version.

CQL and CQLinq

Past versions of NDepend have had a built-in language for generating code metrics, called Code Query Language (CQL). A sample for generating warnings on unsealed classes with no subclasses looks like:

// <Name>Class with no descendant should be sealed if possible</Name>
WARN IF Count > 0 IN SELECT TOP 10 TYPES WHERE 
  IsClass AND 
  NbChildren ==0 AND 
  !IsSealed AND 
  !IsStatic 
  ORDER BY NbLinesOfCode

Recent versions of .NET languages C# and VB have supported the use of Language Integrated Query (Linq) for querying collections and retrieving matches using a syntax similar to Structured Query Language (SQL). A CQLinq analog to the above CQL sample follows:

// <Name>Class with no descendant should be sealed if possible</Name>
warnif count > 0 from t in JustMyCode.Types where 
  t.IsClass && 
  t.NbChildren ==0 && 
 !t.IsSealed && 
 !t.IsStatic 
  orderby t.NbLinesOfCode descending
select new { t, t.NbLinesOfCode }

It seems that one option is not better than the other, yet the CQLinq format closer resembles what C# developers will be used to writing. That alone may make using the new format worthwhile. Both versions – CQL and CQLinq – are being supported, though the CQLinq may be a natural selection for those used to the Linq syntax.

The CQLinq syntax is well-documented on the NDepend website. There is also some documentation on converting CQL rules into CQLinq equivalents.

Other Changes

CQLinq is possibly the most notable change in this version of NDepend. There are other changes worth pointing out, however, which further improve the utility of the tool. One of these is integration into other tools.

NDepend supports integration with Visual Studio 2008, 2010, and 2012. By installing the integration extension, an NDepend menu appears in the selected Visual Studio versions. This works even if multiple supported versions of Visual Studio are installed – NDepend can integrate with any and all of the three. The menu provides options to create an NDepend project, analyze selected solutions, projects, or assemblies, or to start the separate NDepend application.

An additional integration is with Reflector, the widely-used assembly decompilation tool. With the integration enabled, right-clicking an assembly in Reflector shows a context menu, which includes an NDepend submenu. This submenu provides options for analyzing the assembly in NDepend, including the dependency matrix and the metric view. This is a timesaver for peeking into third-party assemblies, or even self-generated ones.

Another notable change is an NDepend API, which can be utilized when writing custom rules. With this capability, it is possible to write power-tools for NDepend to add rules for running analyses. Installed power tools can be accessed from NDepend’s File->Start Power Tools menu option. This brings up a command-line window with a prompt for running tools of interest, as seen below.

A console window lists NDepend's power toolsThe console window providing access to NDepend’s power tools

NDepend’s report-generation capability has been updated. In version 2, reports were static HTML documents with some images and styling. In version 4, NDepend’s HTML-based reports have some interactivity to show and hide items of interest, as well as some refreshed styling.

Final Thoughts

The user interface doesn’t seem to have changed much. It is still a complex experience as implied in the previous review, and requires some learning before it becomes familiar. It is also best used on larger screens where there is more space to work with – the different panels quickly crowd smaller displays.

Once understood, the UI makes analyzing assemblies, running rules, and generating reports easy. That was the case previously, it still is now. The new CQLinq syntax for writing analysis rules, along with the API, make code analysis a (somewhat) easier task than it was previously. These all make the new version of NDepend worth taking a look.

Further Reading

There are numerous articles online on the use of NDepend’s features. Some interesting ones are linked here. In particular, go to Patrick’s website and review the posts archive for the second half of the year 2012; there are a number of useful posts about putting NDepend to work.

DotNetBase folders

A .NET Project Base

I’ve written in the past about structuring .NET projects and automating build processes. Setting up the directory structure, as well as the tooling, gets tedious quickly when spinning up multiple projects. I decided to create a “base” project structure to provide a shortcut when starting future projects. (more…)

Viewing coverage results

Using the new NCover

Introduction

I’ve been using NCover for some time, specifically the free version, to gather test coverage statistics when I run my unit tests. I even wrote about it some time ago in my series on .NET tooling and build automation. That’s worked well since, but the free version has not been updated, and is not compatible with .NET 4. As a result, I decided to take a look at the newer commercial version.

To start, I’ll briefly introduce NCover and provide an overview of the latest version. Later on I’ll show how to integrate it into an automated build using NAnt. (more…)

Review: NHibernate in Action

Cover of NHibernate in Action

Authors: Pierre Henri Kuaté, Tobin Harris, Christian Bauer, Gavin King
Publisher: Manning
Published: 2009
Pages: 367

NHibernate is an Object/Relational Mapper (ORM) for .NET applications. It is a complex tool, and trying to piece together useful information gleaned from the web has been frustrating. So I decided to pick up this book. (more…)

NUnit for .NET 4

I’ve written about running unit tests with NUnit before, via a task in a NAnt build file. While upgrading my .NET projects to .NET 4, I found out that NUnit usage needs to be slightly updated as well. (more…)

Reducing Code Coupling – Inversion of Control

Introduction

This series started with describing code coupling and why it should be kept low. Later posts covered how to reduce coupling through use of a service locator and dependency injection.

This particular installment is going to explain Inversion of Control (hereafter generally called IoC), how it relates to the previous techniques, and why it is overall a better solution. (more…)

One of Sandcastle's output capabilities: a website

.NET Projects: Generating Documentation with Sandcastle

Introduction

It’s been a little while since I last wrote an article for my .NET tooling series. The series up to this point has included the following steps:

I’ve finally gotten to writing up an important part of the build process: documentation. This is a big article, but it forms an important piece of the puzzle that is software development.

An important part of software projects is documentation; this includes end-user documentation and technical documentation. The latter usually includes API documentation, which is important for developers working to maintain or extend existing software. There are a number of large-scale API documentation repositories, including, but not limited to, the Java docs and MSDN.

Such documentation can be done within your code, in the form of comments. You can then use a tool to extract those documentation comments and convert them into other formats such as HTML or CHM. Since I’ve been on a .NET bent in recent years, I’ll show how to generate documentation from code written in C#.

(more…)

Zip file generated by package task

.NET Projects: Packaging Your Build

Introduction

In the past, I’ve talked about using NAnt to automatically prepare and build your application. The use of NAnt does not end once the compile has completed, however. Sure, you’ll want to run tests and analyses, generate documentation and so on, but the end point of the cycle is usually packaging the artifacts for distribution. I’ll show a task that can be used to generate a Zip file of your build results. (more…)

Page 1 of 3123