Convert string to Guid

This blog descibes how you can convert a string like "Alex" to a Guid with value: 1fe62611-cd3f-46e3-1e09-0ccb19e446e7. The same string always results in the same guid.

More..

SequentialGuid version 2, with IComparable and creation date and time

In an earlier post I compared the performance of Int (with autonumber) and a (Sequential) guid in SQL server. I posted an implementation of a C# SequentialGuid that created Guid's that were sequential, but they where still regular Guids. Once you had a Guid, it was just a regular Guid with the last 6 bytes ordered. The new version is a wrapper around the Guid with some cool extra stuff.

More..

Add context to IEnumerable<> elements

Elements of an IEnumerable sequence do not know about the other elements. I often need to compare an element with a previous or next element. Sometimes I need other context like all the other elements, the previous elements or if an element is the last element. That is why I use an extension method that adds context to all elements.

More..

Random password generator with numbers and special characters

I saw many password generators but none of them did what I needed. Also it was often not random enough and/or unnesessary complex. So I created my own password generator. It has parameters for the lenght of the password, the minimum lowercase, uppercase, numbers and special characters.

More..

Paging with Linq to objects

Paging with Linq (to objects) seems quite simple: This is handy when you need a page 'in the middle only' but if you need to enumerate all pages, you have to caculate the number of pages yourself. The next method will help you to get all pages:

More..

Ultimate command line arguments parsing: query with Linq

Command line parsing in C# is (static void Main(args []string) is very limited. That is why I created a ParameterParser class that results a list of Parameter objects that can be queried with Linq. An example:

More..

Lazy<T> property caching alternative

Lazy is a handy class, available since .NET 4.0. It has only one big disadvantage: if you use it to cache a property and it uses other members of the class, you need to implement the property in the constructor. An example:

More..

Create your own navigation system (with a Graph, Node and Connection class)

Lots of people uses naviagtion systems like TomTom these days. As a C# deveoper you might want to know what the basic principles are behind these systems. This post shows you 3 fully functional classes behind the principles of a navigation system.

More..

Simple IoC container, makes it easier to debug

There are already many frameworks to support Inversion of Control (IoC). Most of the frameworks use reflection and use their own code to create a new object. This makes it harder to debug your code and you have no control about how the object is created.

More..

Permutations and missing values, helpful with unit testing

Creating of unit tests of a method with 1 bool parameter needs at least 2 unit tests (false and true). But how many unit tests do you need for a parameter of type IEnumerable? A variant of the Permutations() method will help you to create almost all necessary combinations with just one extension method!

More..

A SOLID validation class

A long story today, but very instructive if you do not have much experience with SOLID. I will give you 2 clues in advance:

More..

ID - Sequential Guid (COMB) Vs. Int Identity, using Entity Framework

Recently i had to choose a type for an Id in a SQL server Database. We are using Entity framework to access the database. I had to choose between Guid an Int. I seems to me that Guid must be a slow solution but in a real world scenario, this was not true (see results later in this blog). First an (optional) small introduction about some terms used here. Then the testresult , folowwing by the C# implementation of a third option, called Sequential Guid.

More..

LazyList<T>: A better LINQ-result-cache than List<T>

While designing a new programming language, I wondered if I would cache query results by default or not. Caching has advantages and disadvantages. I Found a solution that has the best of both worlds. The solution is also possible in C#!

More..

Except, intersect and union without distinct

Immaging that you have a customer that should pay you €10, €10, €20, €30, €30. He already paid you €10, €20. You need to know what he still needs to pay you. How will C#/LINQ helps you to give the answer?

More..

A generic tree of nodes, the easy way!

Today I saw a Stackoverflow-post about a genaral solution for tree and nodes. It reminds me of a solution I created to store departments in tree. I was surprised that no standard .NET collection does exactly what I need, so I created my own Node. It has properties like:

More..

Mapping without the switch command

In a project I had to map a lot of external codes and values to our codes and values. This results in methods with switch statements:

More..

Any, Single, Multiple and Count

In a collection we can easily check if there is any (particular) item: This is a very efficient way to check because it doesn't enumerate the whole collection. After enumerating the first element, the Any() method returns the result. This saves time if the collection is large or enumeration goes slow.

More..

Enum to dictionary

In a previous project we stored the values of an enum in a database. That made it easy to fill listboxes and comboboxes. It also helps to ensure data integrity. Storing enums means a violations of the most important rule for developers: single point of definition.

More..

Convert to unknown generic type: ChangeType<T>

When you create a generic method (Foo) or generic class (Bar), it often happens that you need to change (or convert) a type to T. In these situations you need a ChangeType function that changes "any" type to T. Unfortunately this is not a standard method. The Cast() method of Linq looks like a solution but it is very limited. This wil not work for a lot of types:

More..