Disable You Have Created a Service

When you create a basic WCF service hosted through IIS, you are greeted with a generic page informing you that “You Have Created a Service”. This is useful since it provides to the developer two critical pieces of information. First it lets you know that the service is up and running, second it provides basic code stubs to query the service with. While this may be fine for development, you might not want to display this page in production. Disabling it is not intuitive, but with some searching through the MSDN documentation I have found the preferred way of changing this page.

Read More
Debugging With Conditionals

So you have your program written out, and you have met all your goals. You are so confident that the program is ready, you rip out the debug statements and other debugging related functionality from it. You fire up the program and feed it the initial values and BAM nothing works! If only you kept the debug calls! Well you can avoid this in the future by using conditions in your code.

Read More
C# Classes Versus Structures

There are a few situations where a C# structure will provided better performance than a C# class and other times a class will be faster than a structure. The reason for this is how C# is handling both of these in memory during program execution.

Read More
A Simple Way to Check for a Table in Access

As I worked on another project today, I came across a simple dilemma. The project reads in a small Microsoft Access database (also known as a .mdb file) into memory. It then queries said database with a simple ‘SELECT foo FROM bar…‘ statement and pulls the results into the program. However, if you load an Access database that does not follow the expected schema, the program throws a nasty error and causes some logic interruption. I needed a simple way to check for a few table names before proceeding, so I whipped up a simple C# method.

Read More
Add Descriptions to Enumerations

Enumerations in C# allow you to group common constants together inside a piece of code. They are often used for determining a system state, flag state, or other constant conditions throughout the program. Usually enums are not formatted for “pretty” displaying to the end user. However you can use a little C# magic to make them behave better with descriptions!

Read More
Access Common Methods Using Extensions

There will be times when you are using a third-party library or some other “black box” software in your project. During those times you may need to add functionality to objects or classes, but that addition does not necessarily call for employing inheritance or some other subclass. In fact, you might not have access to the library’s source code if it is proprietary. There is a wonderful feature of C# though that allows you to add-on commonly used methods to any type of object, and that feature is called Extension Methods

Read More
How To: Create a Visual Studio 2010 Code Snippet

As you work through various projects in Visual Studio 2010 you will find yourself reusing a lot of code. In fact, you may find yourself reusing a lot of the same static code, or code that follows a basic pattern. Visual Studio 2010 lets you cut out a lot of this wasted time by employing code snippets. Code snippets can generate basic code patterns or layouts on the fly inside your project. Today I will walk you through creating a basic code snippet for generating a C# class with specific section stubs.

Read More
A XAML DataGrid Quirk

Everyone knows how amazing XAML is to create flexible and beautiful GUI’s for various applications. XAML provides a wonderful interface to building a simple grid of data (much like an Excel spreadsheet) with the DataGrid namespace. I was working on a DataGrid object in one of my projects today, and chose to re-work the XAML into a better form for easier reading and code re-use. I however stumbled into a strange characteristic of the Datagrid, and I wanted to share with you that issue and the fix I came up with.

Read More
Using #region Effectively

The #region preprocessor directive can make your C# code very organized. It is a shame that so many coders do not learn to use #region early and often. Sure #region allows Visual Studio 2010 to collapse your code block down into one-line, but better yet it can be used to sort code by common sections. This provides a framework for other source files throughout your project to mimic. Today I wanted to cover how I like to sort my code in my projects.

Read More
Visual Studio 2010 Document Previews

If you have used Visual Studio 2008 or the Visual Studio 2010 Betas you should remember a distinct feature. When you moved through documents inside the IDE with CTRL + TAB you would get a nice little preview of the documents you were flipping through. If you have used the latest version of Visual Studio 2010, you may have noticed that this feature has been pulled. Well you can restore it with a simple registry change!

Read More