Macros for C# 5.0
With the release of new features in C# 4.0, it's natural to start looking ahead to the future and speculate on what kinds of features might be added to the language with the next release. The idea of integrating compilation as a runtime service has already been raised, by Anders Hejlsberg no less, though we have as yet (late 2010) no information about what that might look like.
In many systems you have a set of related classes that have fixed relationships with each other. To illustrate, start with a domain class Person that encapsulates the concept of a person. Add a repository interface IPersonRepository and associated implementation PersonRepository to provide persistence functionality in our database of choice. Introduce a web service defined by IPersonServices that provides access "over the wire" to our system, using data transfer object PersonData to provide a representation of our domain classes.
As anyone used to using Code Generation tools can testify, these classes might all have different roles and different functionality, but they can all be mechanically derived from the original base definition. While I've long been a proponent of using code generation and related techniques to boost productivity, I'm also of the opinion that we wouldn't have a strong need for these tools if the underlying language was sufficiently powerful.
Taking a lead from the idea of "compilation as a service", I've identified a way to boost the power of the C# language by incorporating ideas from the compiler into the runtime experience in a way that renders a significant amount of code generation obsolete.
In this series, I'll explore my ideas about these potential improvements to C#.
Before I start writing further, a small disclaimer: These are my ideas on one way to extend the C# language in a useful way. While I've thought through many of the issues and come to conclusions that are satisfactory to me, there are bound to be cases I've not considered. It may be that the ideas I have are heroically bad, and I just don't realise it. Lastly, I'd be very surprised if the actual mechanics of C# 5.0 look anything like this. But, I can hope.

Recent comments
29 sec ago
11 hours 7 min ago
6 days 8 hours ago
1 week 11 hours ago
1 week 1 day ago
1 week 2 days ago
2 weeks 3 days ago
10 weeks 5 days ago
18 weeks 3 days ago
18 weeks 3 days ago