Using advanced features in the real world

time to read 8 min | 1596 words

Many of the new features of C# 2.0 seems to be targeted toward a very spesific problem. Here is a short list of the things that I've seem. It just the feature, the target it's used for, and what I am using it for in a real project. When I'm talking about the intended usage, I'm talking about the main problem this feature is aimed to solve, and I deduct that simply by looking at where the most examples of it are.

Feature Problem it is solving What I am using it for
Generics Strongly typed Collections without custom classes.
Casting hell.
  • Database persistance layer that allow for some really funky stuff to happen under the cover while giving you the impression that it's all the same thing.
  • UI Controls for business objects and custom types - one type of control that handles a lot of the types cleanly.
Anonymous delegates Signle line event hanlders requiring their own method.
  • Passing logic around for classes to act upon.
  • Customizing a class without inheritance, by adding a piece of external code that can participate in the action.
  • Pushing policy decision to higher layers, while keeping the details on a lower layer.
Nullable types Database persistance for value types
  • Terenary bool and guard values for integers
Yield return Simplifying iterations over complex graphs
  • Making very complex object graph iterations very simple.
  • Lazily evaluating processing logic, combined with delegates, this one is a killer.

Just to clarify, I don't think that I'm doing anything special, but I do think that I'm putting some of the features to use in different context than what most people expect. So far I didn't have any problem in explaining my logic to other people, and I feel that it certainly help in encapsulating a whole lot of trouble in really elegant ways.

What unusual things are you doing with the new features?