Well we're not quite a decade yet--certainly a lot longer than five years, though--since .NET came out and promised to be the next big thing for programming. C# was supposed to put VB6 to shame. It didn't, though, because with VB6 you had such things as optional parameters and variants--the latter being an ugly beast but under the covers the flexibility that VB6 was made programming so much quicker and easier sometimes.
Now that C# 4.0 introduces optional parameters and dynamic objects, the whole playing field is changing. And now I can feel a bit freer to tinker with old-school technologies built on COM in my language of choice because the language has finally caught up with last decade's featureset in this respect.
I like this somewhat recent blog post by SamNG:
http://blogs.msdn.com/samng/archive/2009/06/16/com-interop-in-c-4-0.aspx
Lets look at a quick Office example.
static void Main()
{
Word.Application app = new Word.Application();
object m = Type.Missing;
app.Documents.Add(ref m, ref m, ref m, ref m);
}
This is such typical code! I have to struggle with the type system to make it happy, just to add a simple Word document!
... [With C# 4.0] in the following code, call (1) gets transformed into call (2).
static void Main()
{
Word.Application app = new Word.Application();
// (1) Your initial call.
app.Documents.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
// (2) Compiler generates locals and inserts them.
object m = Type.Missing;
app.Documents.Add(ref m, ref m, ref m, ref m);
}
The great thing about this too, is that with the introduction of named and optional arguments, and using the fact that the feature generates Type.Missing in place of default values for object on COM types, we can simply remove the arguments altogether!
static void Main()
{
Word.Application app = new Word.Application();
// (1) Your optional-parameter-omitted initial call.
app.Documents.Add();
// (2) Compiler generates locals and inserts them.
object m = Type.Missing;
app.Documents.Add(ref m, ref m, ref m, ref m);
}
Pretty cool stuff huh? Definitely makes programming against the Office APIs much nicer.
Yup. Indeed.