Type Alias Quirk
Scott Hanselman tweeted this afternoon about it being a drag using a type like this:
List<KeyValuePair<String, Func<Brush, UserControl>>>
It's certainly a complex type with all those nested generics. My first instinct, apart from deriving new non-generic classes from the generic ones, was to try type aliases to simplify the declaration. This first try worked:
using BrushUserControlFunc = System.Func<
System.Windows.Media.Brush,
System.Windows.Controls.UserControl>;
With that code outside of my namespace declaration, I was free to declare a type like this:
List<KeyValuePair<String, BrushUserControlFunc>> foo;
Still pretty ugly though, so logically the next thing to do would be to alias off the KeyValuePair type. That's where I struck a hurdle. This doesn't compile:
using BrushUserControlFunc = System.Func<
System.Windows.Media.Brush,
System.Windows.Controls.UserControl>; using StringFuncPair = System.Collections.Generic.KeyValuePair<
string,
BrushUserControlFunc>;
It seems that you can't make one aliased type the generic parameter to another. Moving the second declaration into my namespace made it work, though:
using BrushUserControlFunc = System.Func<So that's a strange quirk with type aliases. It's a hell of an edge case, but there you go.
System.Windows.Media.Brush,
System.Windows.Controls.UserControl>; namespace WpfApplication1 { using StringFuncPair = KeyValuePair<string, BrushUserControlFunc>;