Strings and string manipulation are a complex and a much larger topic than it appears on the surface. There are many different complicated scenarios when using strings and their very nature is often misunderstood. What makes strings different? Strings are immutable which means they are read-only. When you alter a string in any way, behind the scenes, the .NET framework …
Events and Delegates in C#
Events and Delegates are two topics in the .NET Framework that are truly misunderstood and many times not understood at all. This post will attempt to explain what events are, how they are related to delegates, and how to use them in your code. What Are Events? Events are a way for objects in the .NET Framework or your own …
The Crazy Dangers of Overcommitment
I am always horrified and somewhat amused at how we (I) become overcommitted. It happens to me far too often and there are a couple of really simple reasons why. While the reasons may be easily understood, they are not nearly as easy to control. Popular Reasons We Overcommit First, saying yes is very easy. Saying no is very hard. There …
Getting Started with AutoMapper
If you are an experienced software developer you have no doubt written thousands of lines of code mapping properties of one object to properties of another object. This is commonly done when creating ViewModel objects or data transfer objects (DTOs). AutoMapper gives you a reusable, elegant solution to this problem. In this post, we will explore how AutoMapper does this. …
An In-Depth Look at ASP.NET MVC ModelState
If you have spent much time around ASP.NET MVC, you have no doubt used ModelState just like all other good little MVC developers. Have you ever peeked under the covers, though, and looked at why and how it works? In this post, we will do just that. What is ModelState? ModelState is, at its core, the values of a form …
An Introduction to the AntiForgeryToken HTML Helper
The ASP.NET MVC AntiForgeryToken HTML Helper is a widely used but not well-understood helper. In this post, I will look at the details of the helper, explain how it works, and how you should be using it. What is the AntiForgeryToken Helper? The AntiForgeryToken helper protects your site from cross-site request forgery. Cross-site request forgery is the process …
A Gentle Introduction to Test Driven Development (TDD)
TDD is all the rage and the best thing since sliced bread. TDD is a terrible abomination that should die a quick but very painful death. TDD is great. TDD is terrible. If you look for information on TDD, you can get all of these opinions and everything in between. This is actually very encouraging. Because there are so many …
The Strategy Design Pattern in C#
The strategy design pattern allows you to encapsulate a group or family of algorithms, making them interchangeable. This allows code to determine which strategy to use at runtime. The strategy pattern is a behavioral pattern and is one of the original design patterns defined by the Gang of Four (GoF). What Problem Does It Solve? The strategy pattern allows …
The Observer Design Pattern in C#
The Observer design pattern is a behavioral pattern and was one of the original design patterns defined by the Gang of Four (GoF). The Observer pattern defines a relationship between a publisher, also known as a subject, and one or more subscribers, also known as observers. In this post, I will describe the pattern and show a sample implementation. What …
The Factory Design Pattern in C#
The factory design pattern is a widely accepted and well-regarded creational design pattern. It is one of the original 23 design patterns from the Gang of Four (GoF). The factory design pattern defines an interface for creating new objects instead of using the new keyword but allows classes that implement the interface to decide which class to instantiate. Simply put, the factory …