C# Musings…

I had a few ideas for C# constructs, so I thought I might as well write them down. Perhaps, some day, someone can tell me why these don’t exist…

Making Generics More Generic

Several times I’ve been frustrated by the fact that Func<TResult> has a bunch of variants. Wouldn’t it be cool it you could specify a generic definition over an arbitrary number of types? This is what I mean:

Func<T, T1, T2, T3, TResult> could become Func<T1, …, Tn, TResult> or perhaps, even better, Func<T[], TResult>. No, I don’t know what the full implications of this type of syntax would be, but from a purely pragmatic perspective, this would be crazy useful.

Extensions (and Partials) Should Fulfill Interfaces

Think about how cool this is.

I’ve run into the problem several times where I have to subclass or wrap an object I don’t own so that it fulfills an interface I do own. Wouldn’t it be cool if, instead, I could use extensions or partial classes to fulfill that interface?

Constraints on Type Parameters Could Be Constraintier

Constraints are so cool, but I often feel limited by the constraints you can put on a type constructor. For instance, I can enforce a default constructor with new(), but I can’t enforce a constructor that takes arbitrary arguments, like new(T1, T2) or even just new(int, float). Wouldn’t that be great?