Archive for 2007

Fun with C# Extension Methods: Easy Ranges

I’m not a real Ruby on Rails developer, but I’ve tried to learn it, just to broaden my perspective. Coming from a C# background, I’m impressed by how easy it is to read Ruby code. In fact, it is usually so compact and self-descriptive, you can understand it just by reading the code. Imagine not [...]

More »

Refactoring C# Series: Use Automatic Property

Name Use Automatic Property Summary You have a property in a class which just wraps a field of the same type, and simply returns or sets that field. private string _field1; public string Field1 { get { return _field1; } set { _field1 = value; } } Becomes: public string Field1 { get; set; } [...]

More »

A Mixin for IComparable<T>

Following on from my other posts on C# Mixins, here’s a short one to demonstrate the benefits of Mixins using IComparable<T>. I don’t know about you, but I can never remember how the CompareTo method of IComparable<T> works. If I remember correctly, it gives back -1 if the value of the compared object is less [...]

More »

A not-so-simple Mixin with C# 3.0

My last post gave a simple idea of how to do a Mixin with C#. Rather than repeating what someone else has already done, if you want to see a more complex example of what can be done, check out Create Mixins with Interfaces and Extension Methods by Bill Wagner at MSDN.com.

More »

A simple Mix-in with C# 3.0

Heard of mix-ins? They’re an alternative to multiple inheritance, made popular recently by Ruby. Basically, you can use them to “mix in” methods from an interface with their implementations into a class. In Ruby you can do this by including a module in a class. In C#, you do it by implementing an interface and [...]

More »

New series: Refactoring C# 1.0 code to C# 3.0

I really like Scott Hanselmann’s idea to write an indefinite series of posts about reading code to be a better developer. I’m going to copy his idea, and write a series of my own. Since its first version, C# has evolved from being a Java clone to something much more dynamic. I’ve noticed that developers [...]

More »

Learning LINQ with LINQPad

I’ve been trying to learn LINQ. Chris Sells recommended C# 3.0 in a Nutshell, which has turned out to be really good. The name of the book doesn’t really do the LINQ part of it any justice – it could have been called C# 3.0 and LINQ, as the LINQ section is so good. If [...]

More »

Qualities of a .Net Application Design

I’m often asked to produce design documents for new applications. I can’t do this without discussing the advantages and disadvantages to each part of the design. A great way to do this is to focus on the desired qualities of the system you’re trying to build. Define the qualities you are trying to achieve, and [...]

More »

ASP.Net MVC Framework leads you to extension method heaven

The first pre-release of new ASP.Net MVC (ahem, Ruby-on-Rails for .Net) framework has just been made public. I find it really exciting that Scott Guthrie and his team are listening to what the people want. Webforms is really quite heavy, especially in comparison to Ruby on Rails, so by offering new frameworks Microsoft will gain [...]

More »