I like Windows Presentation Foundation (WPF) very much, especially its implementation of the Model-View-Controller (MVC) design pattern. I've also grown to appreciate XAML as a declarative (if quirky) way of building complex user interfaces that integrate with a testable code file. However, every once in a while, I end up with a WPF Window that takes a long time to render, or renders in a bizarre series of jumps. If that's happened to you, it's worthwhile to download Microsoft's WPF Performance Suite.
More
Posted by Peter Vogel on 01/13/20140 comments
The ability to nest one class inside provides a powerful way to encapsulate code inside a class to organize complex functionality used within a single class. A nested class looks like this:
Public Class MyClass
…code for the class…
Class MyNestedClass
End Class
Public Sub SomeMethod()
Dim mnc As MyNestedClass
mnc = New MyNestedClass()
…using the nested class…
End Sub
End Class
More
Posted by Peter Vogel on 01/09/20140 comments
If you miss the free version of Reflector now that Red Gate's taken it over, and if you don't appreciate the functionality that Red Gate has added to it, then ILSpy is for you.
ILSpy will decompile any .NET DLL back to either Visual Basic or C# (your choice), and provide a viewer that lets you browse the results. If you want to find out how the code behind the framework DLLs works (or if you've just lost your source code), ILSpy will let you see it. There are even a few plugins for ILSpy that enhance the basic package (and they're also free).
More
Posted by Peter Vogel on 01/08/20140 comments
Over a series of articles about commenting, I discussed why the key issue is to write ROC (Really Obvious Code). If you do, then the only comments you need to provide for your methods should be what parameters the method expects, what your method will do with those parameters, what the method will return, and any side effects of executing the method (e.g., database updates). If you bought into that plan (and some readers did not), then the best place to put that documentation is where Visual Studio will make the best use of it: in IntelliSense, by using XML comments.
More
Posted by Peter Vogel on 01/07/20140 comments
You're working with a variable, property, method or class and you need more information about it. If you hover your mouse over the item's name, IntelliSense displays the information for you. But when you need more information or, especially, if you want to make some changes to the item, clicking on the item's name and pressing F12 will take you to it.
More
Posted by Peter Vogel on 12/09/20130 comments
Like everyone else, I like code-first Entity Framework (EF) development because it makes it so easy to integrate custom code with my EF entity code. But even in a pure code-first development, I suspect that most developers don't generate their databases from their entities because, most of the time, the database already exists (and, besides, the DBA won't let developers anywhere near the database's schema). That means you have to write all the repetitious property declaration in the entity objects to mimic the tables you'll be working with. Wouldn't it be nice if you had a tool to do it for you?
More
Posted by Peter Vogel on 12/04/20130 comments
I've been working on a Windows Forms application for one of my clients and, in the application, I use the CheckedBoxList and the DataGridView. Both of them have really useful collections: the CheckedBoxList has a CheckedItems collection that holds all the items that the user has checked, and the DataGridView has a SelectedRows collection that holds all the rows the user's selected, for instance. The CheckedItems collection can hold any object I want while the SelectedRows collection holds DataGridViewRow objects.
More
Posted by Peter Vogel on 11/15/20130 comments
About a year ago, Patrick Steele did a great job of describing AutoMapper: an absolutely necessary tool if you're using Data Transfer Objects to move data between parts of your application. AutoMapper will automatically move data from your business entities into the corresponding properties on your DTO, saving you many, many lines of repetitious assignment statements. It also means that if you add a new property to your DTO, AutoMapper will automatically pick up the corresponding property from the entity; no further changes to your code required.
More
Posted by Peter Vogel on 11/06/20130 comments
I'm sure that by now, mentioning these three tools is almost redundant, but even if you're working on a single computer on your own, Subversion lets you have as much (or as little) source control as you want. Subversion is ridiculously easy to install and start running.
More
Posted by Peter Vogel on 10/30/20130 comments
This isn't so much a tip as a clarification: I often find that people are confused about what happens when you press F5 vs. when you press Control_F5. Here's the best description I've found (and it's from the blog where I've found most of the Visual Studio tips that I talk about here).
More
Posted by Peter Vogel on 10/22/20130 comments
I know that Windows Forms are considered old fashioned, but I've got clients with applications that still use them. As I noted in my previous tip, I recently had to support letting the user sort by any column in a grid. If I was going to do that, I felt I should let the user know what column and direction they'd just sorted the grid in. The DataGridView lets you do that through the column's SortGlyphDirection property: just set the property to one of SortOrder.Ascending (little arrow in the column header pointing up), SortOrder.Descending (little arrow pointing down), or SortOrder.None (no arrow in the header).
More
Posted by Peter Vogel on 10/17/20130 comments
In the bad old days (before LINQ), I used to concatenate together SQL statements. That left me open to SQL injection attacks, of course, but it was so convenient: I could dynamically put together whatever SQL I needed at runtime. With LINQ, however, not so much (though I understand that there is a version of Dynamic LINQ out there). Even with ordinary LINQ, though, you can select which properties in an object you want to use at runtime; at least when you're sorting (and, probably, elsewhere but I haven't tried it yet).
More
Posted by Peter Vogel on 10/07/20130 comments