Thread Safe Generic Weak Dictionary in .NET

If you are about to begin implementing your own version of a thread safe generic weak dictionary – STOP!

As of .NET 4.0, there is already one:

System.Runtime.CompilerServices.ConditionalWeakTable<TKey, TValue>

Now that .NET 4.5 has been made open source few weeks ago, we can look at the comments and more importantly at the implementation of ConditionalWeakTable<TKey, TValue>. Continue reading “Thread Safe Generic Weak Dictionary in .NET”

Design patterns and practices in .NET: the Chain of Responsibility pattern

Exercises in .NET with Andras Nemes

Introduction

The Chain of Responsibility is an ordered chain of message handlers that can process a specific type of message or pass the message to the next handler in the chain. This pattern revolves around messaging between a sender and one more receivers. This probably sounds very cryptic – just like the basic description of design patterns in general – so let’s see a quick example in words.

Suppose we have a Sender that knows the first receiver in the messaging chain, call it Receiver A. Receiver A is in turn aware of Receiver B and so on. When a message comes in to a sender we can only perform one thing: pass it along to the first receiver. Receiver A inspects the message and decides whether it can process it or not. If not then it passes the message along to Receiver B and Receiver B will perform the…

View original post 1,152 more words

Extracting information from a text using Regex and Match in C# .NET

Regex has never been easy for me for some reason :/

Exercises in .NET with Andras Nemes

Occasionally you need to extract some information from a free-text form. Consider the following text:

First name: Elvis
Last name: Presley
Address: 1 Heaven Street
City: Memphis
State: TN
Zip: 12345

Say you need to extract the full name, the address, the city, the state and the zip code into a pipe-delimited string. The following function is one option:

Call the function as follows:

View all posts related to string and text operations here.

View original post

Blog at WordPress.com.

Up ↑