Nov
13
2008
0

ReSharper Tip of the Day: Put into ‘using’ construct.

There has been some debate if you need every IDisposable should be disposed. From the documentation IDisposable is used to clean up any unmanaged resource.

Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector.

OK. That’s fine. I totally agree with that until I see DataTable is derived from a class, MarshallByValueComponent, that implements IDisposable. Does that mean DataTable has unmanaged resources? Any way, on to the tip.

ReSharper notices when an object is created that implements IDisposable and it can automatically wrap the usage in a using block. Say you have the following code:

…and want to put it in a using block. Trusty ALT+Enter steps in a gives you the following options:

It is creates a nice using block around the object and all of its usages.

What would really be nice is we could create a warning when we see ourselves using an IDisposible without calling Dispose. That might be more difficult than finding one outside of a using. We could be calling Dispose in a try/finally or somewhere else.

Written by mark in: ReSharper Tip of the Day | Tags: ,
Oct
08
2008
2

ReSharper tip of the Day: Move Code Left and Right

Josh showed us how to slap around our code with CTRL+ALT+SHIFT+UP|DOWN. We can now smack around our markup a little further. In addition to the four fingered up and down bully job, we and take an attribute left or right in the pecking order of the opening tag.

CTRL+SHIFT+ALT+LEFT|RIGHT (right in this case) bumps the attribute over.

If you prefer a more vertical representation of the attributes like the following, the command still works, but less intuitive since left and right actually move it up and down, and up and down move the entire tag up and down.

<CheckBox
     Margin="0,0,0,0"
     Unchecked="DoUnchecked"
     Checked="DoChecked">
     Some Text
</CheckBox>

One last thing to note is you do not need to select the entire attribute. Having the cursor in the attribute you wish to move is enough.

Written by mark in: ReSharper Tip of the Day | Tags: , ,
Sep
04
2008
0

Visual Studio Tip of the Day: Evaluative Comments

I’m not sure where I originally saw this, but it was most likely Sara Ford’s blog. She has tons of great Visual Studio tips.

You can evaluate comments in code while debugging by highlighting them and hovering over them. 

 

Written by mark in: Tips | Tags: ,
Sep
03
2008
1

Visual Studio Tip of the Day: Cycle Clipboard Ring

In conversation Sean pointed out that Emacs has a clipboard ring that will allow you to cycle through the most recent copied/cut items and the Visual Studio had similar functionality. I immediately went to find it and was shocked to see it right there in the Edit menu.

Pretty simple. Ctrl+Shift+V will paste and then select the previous item in the clipboard ring. To repeatedly paste the item once you found it you can switch to Ctrl+V.

Tomorrow’s tip: The Del key will delete the selected text. See the same screenshot.

Written by mark in: Visual Studio | Tags: ,
Aug
13
2008
0

ReSharper Tip of the Day: Generate Equals

We’ve all probably had really basic POCO classes like this:

public class Fooberry
{
    public string Foo { get; set; }
    public string Bar { get; set; }
}

…and we’ve probably had to override Equals on them. When I went to go do it this last time, I saw ReSharper was trying to help me out.

So I expanded the context icon to see what it would do for me. It turns out it does something really cool.

It will complete the Equals statement for me! Awesome! I hate writing that method over and over.

Yes…I would like to compare those items…and we’re done!

public override bool Equals(object obj) {
    if (ReferenceEquals(null, obj)) return false;
    if (ReferenceEquals(this, obj)) return true;
    if (obj.GetType() != typeof (Fooberry)) return false;
    return Equals((Fooberry) obj);
}

public bool Equals(Fooberry obj)
{
    if (ReferenceEquals(null, obj)) return false;
    if (ReferenceEquals(this, obj)) return true;
    return Equals(obj.Foo, Foo) && Equals(obj.Bar, Bar);
}

public override int GetHashCode()
{
    unchecked
    {
        return ((Foo != null ? Foo.GetHashCode() : 0)*397) ^ (Bar != null ? Bar.GetHashCode() : 0);
    }
}

Pretty awesome if you ask me! The only downside is if I add new members to the class, I need to either add the tests in manually or generate the whole thing.

Steve (a co-worker)’s sharp eye noticed the unchecked keyword, and neither of us has used it so after looking it up it avoids overflow checks and trunks anything that would exceed normal bounds.

Written by mark in: ReSharper Tip of the Day | Tags: ,

Powered by WordPress | Kredit | TheBuckmaker