I've seen lots of answers to the typedef
problem in C#, which I've used, so I have:
using Foo = System.Collections.Generic.Queue<Bar>;
and this works well. I can change the definition (esp. change Bar => Zoo etc) and everything that uses Foo changes. Great.
Now I want this to work:
using Foo = System.Collections.Generic.Queue<Bar>;
using FooMap = System.Collections.Generic.Dictionary<char, Foo>;
but C# doesn't seem to like Foo
in the second line, even though I've defined it in the first.
Is there a way of using an existing alias as part of another?
Edit: I'm using VS2008
Aliasing: Aliasing refers to the situation where the same memory location can be accessed using different names. For Example, if a function takes two pointers A and B which have the same value, then the name A[0] aliases the name B[0] i.e., we say the pointers A and B alias each other.
An alias occurs when different variables point directly or indirectly to a single area of storage. Aliasing refers to assumptions made during optimization about which variables can point to or occupy the same storage area.
According to the standard it looks like the answer is no. From Section 16.3.1, paragraph 6:
1 The order in which using-alias-directives are written has no significance, and resolution of the namespace-or-type-name referenced by a using-alias-directive is not affected by the using-alias-directive itself or by other using-directives in the immediately containing compilation unit or namespace body.
2 In other words, the namespace-or-type-name of a using-alias-directive is resolved as if the immediately containing compilation unit or namespace body had no using-directives.
Edit:
I just noticed that the version at the above link is a bit out of date. The text from the corresponding paragraph in the 4th Edition is more detailed, but still prohibits referencing using aliases within others. It also contains an example that makes this explicit.
Depending on your needs for scoping and strength of typing you might be able to get away with something like:
class Foo : System.Collections.Generic.Queue<Bar>
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With