# Friday, September 12, 2008

TechEd Online Prism Session is live

Glenn Block (Microsoft) and I did a video interview on buidling composite WPF applications with WPF at TechEd this year, and that interview has now gone live. You can find it in various formats off the TechEd Online landing page or here is a direct link to the low res version.





Friday, September 12, 2008 3:43:45 PM (GMT Daylight Time, UTC+01:00)
Comments [0]  | 


 # Tuesday, September 2, 2008

MSDN Magazine Article Live - Routed Events and Commands

My article on WPF Routed Events and Commands has gone live at http://msdn.microsoft.com/en-us/magazine/cc785480.aspx. In the article I discuss both how to use them, what is going on under the covers, and how to go beyond their limitations.

 

Also be sure to check out Glenn Block's article on Prism in the same issue: http://msdn.microsoft.com/en-us/magazine/cc785479.aspx





Tuesday, September 2, 2008 3:02:09 PM (GMT Daylight Time, UTC+01:00)
Comments [0]  | 


 # Monday, September 1, 2008

Custom Refactor Pro Plug-in - Convert Property

UPDATE: Thanks to some excellent feedback from Rory Becker, I changed my plug in from a Refactor provider to a Code provider. A refactoring should be structural and should not change the functionality of the code, whereas this plug in changes behavior. That just means the prompting is a little different as shown in the updated screen grab below. I also made it work for VB as well with some more help from the DevExpress folks. The code download at the bottom gives you the latest version.

Something I frequently find myself doing is starting a type out with simple, auto-implemented properties in C# along these lines:

public string Name { get; set; }

 

Then at some point I realize I want that type to implement INotifyPropertyChanged and have that property and possibly some of the others raise PropertyChanged notifications when they change. I got really tired of doing this manually, and my first way of automating it was to just create a code snippet for a property changed notification property, and I would overwrite the simple property with the property changed property.

But then I found myself needing to see if INotifyPropertyChanged was already implemented, if not add it, resolve it, see if the property already had a backing member variable, if not add it, yadda yadda... screaming for automation.

Unfortunately code snippets in VS are not that powerful, but fortunately I already use a tool that I think every developer should have on their desktop - CodeRush + Refactor Pro.

These two products are built on top of an extensibility engine called DxCore, which allows them as well as VS to be extensible based on a fairly straightforward API (that is all managed code, unlike the VS extensibility model).

In this case what I really wanted was an intelligent refactoring where I could just right click on an existing property, have it figure out if it had a member variable or not, if not add one, see if the type had INotifyPropertyChanged implemented, if not add it, add the using statement for System.ComponentModel if it was not already there, and add the PropertyChanged event with an anonymous method subscriber (so that you don't need to null check and don't have to worry about multithreaded race conditions with unsubscribing).

With a few hints and a starter project from my friends at DevExpress I got a Refactor Pro plug-in working in no time that does just that. I can invoke Refactor Pro (keystroke or a mouse click) on a simple property (auto-backing member or not) and get this:

refactor

When I invoke the conversion, it adds the INotifyPropertyChanged implementation if needed. So the following simple class:

public class Customer
{
    public string Name { get; set; }
}

 

Becomes this:

public class Customer : INotifyPropertyChanged
{
    string m_Name;
    public string Name
    {
        get
        {
            return m_Name;
        }
        set
        {
            if (value != m_Name)
            {
                m_Name = value;
                PropertyChanged(this, new PropertyChangedEventArgs("Name"));
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged = delegate { };
}

It also adds the using statement for System.ComponentModel if not already present. If I invoke it on another simple property in that class, it just adds the expanded property syntax and leaves the type declaration alone.

The code is a little too long to list here, but you can download the plug-in code here. If there is enough demand through comments, I'll do a follow on post with a walk through of the code.





Monday, September 1, 2008 11:41:58 PM (GMT Daylight Time, UTC+01:00)
Comments [0]  | 

Accelerating Code Analysis and Improving Code Quality with NDepend

I've been working on a project for a customer where a fairly large pile of code has been written by an offshore vendor and I was brought in to do a code review and some clean up and verification of the logic. As I dove into the code, the smells started to become overwhelming.

Trying to work through the entire code base and figure out where to focus my clean up efforts first was a daunting task. However, a wonderful tool called NDepend came to the rescue. If you haven't ever heard of this awesome tool and you have oversight responsibility for a team of developers, you should really check it out.

I can't show screenshots here because the code has namespaces that reveal the client name, but you can find a number of screenshots on the NDepend site itself.

Basically NDepend will do a static analysis of your code base and help you identify everything from tightly coupled code containing too many dependencies (thus the name), but tons of other code metrics including line of code count, cyclomatic complexity, and others. It has a rich interactive UI for drilling into the code from the graphical charts that present you color coded views of where you need to focus as well as a web report generated view that you can view through a browser. You can analyze the code through a number of metrics, and it comes with a powerful query language called CQL (Code Query Language) that lets you look for particular patterns that you want to focus on.

I'd say this is a tool any technical lead, senior developer, or architect in charge of code quality should have in their toolbox.





Monday, September 1, 2008 5:31:08 PM (GMT Daylight Time, UTC+01:00)
Comments [0]  | 


















June, 2013 (1)
May, 2013 (2)
April, 2013 (2)
March, 2013 (2)
February, 2013 (2)
January, 2013 (2)
December, 2012 (3)
November, 2012 (1)
October, 2012 (1)
August, 2012 (2)
June, 2012 (2)
May, 2012 (3)
April, 2012 (1)
March, 2012 (2)
February, 2012 (2)
January, 2012 (1)
November, 2011 (4)
October, 2011 (1)
September, 2011 (2)
August, 2011 (1)
July, 2011 (1)
May, 2011 (5)
March, 2011 (4)
February, 2011 (2)
January, 2011 (3)
November, 2010 (4)
October, 2010 (1)
September, 2010 (5)
August, 2010 (5)
July, 2010 (6)
June, 2010 (8)
May, 2010 (2)
April, 2010 (2)
January, 2010 (1)
December, 2009 (3)
November, 2009 (2)
October, 2009 (3)
September, 2009 (3)
August, 2009 (2)
July, 2009 (3)
May, 2009 (3)
April, 2009 (2)
March, 2009 (1)
February, 2009 (2)
January, 2009 (2)
December, 2008 (1)
November, 2008 (2)
October, 2008 (5)
September, 2008 (4)
August, 2008 (2)
July, 2008 (1)
June, 2008 (2)
May, 2008 (2)
April, 2008 (3)
February, 2008 (6)
January, 2008 (3)
December, 2007 (1)
November, 2007 (1)
October, 2007 (5)
September, 2007 (1)
July, 2007 (3)
June, 2007 (8)
April, 2007 (2)
March, 2007 (4)
February, 2007 (1)
December, 2006 (2)
November, 2006 (9)
October, 2006 (5)
September, 2006 (3)
August, 2006 (2)
July, 2006 (4)
June, 2006 (5)
May, 2006 (10)
April, 2006 (4)
March, 2006 (2)
February, 2006 (12)
January, 2006 (7)
December, 2005 (2)
November, 2005 (15)
October, 2005 (6)
September, 2005 (7)
August, 2005 (3)
July, 2005 (10)
June, 2005 (11)
May, 2005 (7)
April, 2005 (8)
March, 2005 (6)
February, 2005 (2)
January, 2005 (6)
December, 2004 (3)
November, 2004 (5)
October, 2004 (2)
September, 2004 (5)
August, 2004 (13)
July, 2004 (6)
June, 2004 (14)
May, 2004 (17)
April, 2004 (12)
March, 2004 (8)
February, 2004 (10)
January, 2004 (14)
December, 2003 (9)
November, 2003 (13)
October, 2003 (3)

Sign In
Copyright © 2006-2012 Brian Noyes. All rights reserved.

designed by NUKEATION STUDIOS