CodeRush Xpress an amazing tool to work with Visual Studio 2008

Today I have came across a tool called CodeRush Xpress, a free AddIn which can be integrated with Visual Studio and make fun of the coding. This is a combined effort which DevExpress have had with Microsoft by leveraging the existing Visual Studio 2008 IDE.

One scenario is very common to all of us when we need to expose the anonymous type outside the method. Then we need to take the pain of declaring the whole class and use instead of anonymous type. Else there are some type cast way of doing it.

CodeRush made this easy for us, and now we can create class out of any anonymous type per say.

Let’s say you have the line,

var obj = new { Id = 1, Name = "Wriju" };

Install CodeRush and put your cursor at “new”, click Ctrl+~ (tilde button above Tab). This will create a whole class for you like,

[DebuggerDisplay("\\{ Id = {Id}, Name = {Name} \\}")]

private sealed class MyClass : IEquatable<MyClass>

{

    private readonly int _Id;

    private readonly string _Name;

    public MyClass(int id, string name)

    {

        _Id = id;

        _Name = name;

    }

    public override bool Equals(object obj)

    {

        if (obj is MyClass)

            return Equals((MyClass)obj);

        return false;

    }

    public bool Equals(MyClass obj)

    {

        if (!EqualityComparer<int>.Default.Equals(_Id, obj._Id))

            return false;

        if (!EqualityComparer<string>.Default.Equals(_Name, obj._Name))

            return false;

        return true;

    }

    public override int GetHashCode()

    {

        int hash = 0;

        hash ^= EqualityComparer<int>.Default.GetHashCode(_Id);

        hash ^= EqualityComparer<string>.Default.GetHashCode(_Name);

        return hash;

    }

    public override string ToString()

    {

        return String.Format("{{ Id = {0}, Name = {1} }}", _Id, _Name);

    }

    public int Id

    {

        get

        {

            return _Id;

        }

    }

    public string Name

    {

        get

        {

            return _Name;

        }

    }

}

There are many more and I will let them published in my blog. But this is a great tool for developers who live their life with VS source code.

Namoskar!!!