I wanted to do
namespace n
{
using TupT = Tuple<TextBox, string, Func<bool>, string>;
// Doesn't compile
// using DicT = Dictionary<Button, TupT>;
// Have to repeat tuple definition: cumbersome and error prone
using DicT = Dictionary<Button, Tuple<TextBox, Func<bool>, string>>;
// ...
}
This is forbidden by par. 9.3.1 of this language spec: http://msdn.microsoft.com/en-us/library/aa664765%28v=vs.71%29.aspx. Generally, type aliases are not visible to other using alias directives. (Generics are actually not an issue, but the demand for aliasing occurs frequently with generics because the type denotations can become complex.)
Why is that so?
Edit: Yes, I know: I can do it differently in a myriad ways. But I'm specifically wondering why I cannot do it this way ;-)
I suppose this restriction is simply to rule out having to worry about situations like the following in the compiler.
Of course the problem is that
X
isC<Y>
isC<C<X>>
isC<C<C<Y>>>
is ...If the language restriction was looser, disallowing only circular using alias directives, the compiler could feasibly handle that. I think this is just a feature with very low priority - the C# language team only has so much time to design and implement features.
If you find yourself utilizing using alias directives very often, it's an indicator that your common using alias directive should really be made into a class. I'm sure
Tuple<TextBox, string, Func<bool>, string>
isn't nearly as descriptive as a tiny four-property model class.