By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

extern alias and dotted names

P: n/a
I'm playing with 2.0's extern alias declarations and the :: operator.
If I have an

extern alias My;

and the My namespace contains a TypeName, I can refer to My::TypeName
.... or to My.TypeName.

I don't quite get this latter usage: I can *not* refer to
global::My.TypeName nor can I refer to global.System.String.

Is My.TypeName an inconsistency, or did I just miss the msdn page that
explains it?

--
<http://www.midnightbeach.com>
Jan 16 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Jon Shemitz <jo*@midnightbeach.com> wrote:
I'm playing with 2.0's extern alias declarations and the :: operator.
If I have an

extern alias My;

and the My namespace contains a TypeName, I can refer to My::TypeName
... or to My.TypeName.

I don't quite get this latter usage: I can *not* refer to
global::My.TypeName nor can I refer to global.System.String.

Is My.TypeName an inconsistency, or did I just miss the msdn page that
explains it?


I'm not seeing the problem you are in a test program with other names.
Here's my code:

Lib.cs:
using System;

namespace Foo.Bar
{
public class Baz
{
public static void SayHi()
{
Console.WriteLine ("Hello alias");
}
}
}

Test.cs:
extern alias Lib;
using System;

namespace Foo.Bar
{
public class Baz
{
public static void SayHi()
{
Console.WriteLine ("Hello");
}
}
}

class Test
{
static void Main()
{
// Warning (unused variable), but don't worry about it
global::System.String foo = "hello";

Foo.Bar.Baz.SayHi();
global::Foo.Bar.Baz.SayHi();
Lib::Foo.Bar.Baz.SayHi();
}
}

Compile:
csc /target:library Lib.cs
csc Test.cs /r:Lib=lib.dll

Output:
Hello
Hello
Hello alias
It still works if I change "Foo" to "My" everywhere.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #2

P: n/a
"Jon Skeet [C# MVP]" wrote:
I'm not seeing the problem you are in a test program with other names.
Here's my code:
[Most of sample snipped]
global::System.String foo = "hello";
// But while you can NOT say
// global.System.String foo = "hello";
Lib::Foo.Bar.Baz.SayHi();


// You CAN say
// Lib.Foo.Bar.Baz.SayHi();
// but not
// global::Lib.Foo.Bar.Baz.SayHi();
What I really don't get is why I can say

Lib.Foo.Bar.Baz.SayHi();

as if the Lib alias were part of the global namespace - yet I can't
say

// global::Lib.Foo.Bar.Baz.SayHi();
// it's NOT part of the global namespace

or

// global.Lib.Foo.Bar.Baz.SayHi();
// Why "Lib.Foo.Bar.Baz.SayHi();" but not "global.System.string"?
--
<http://www.midnightbeach.com>
Jan 16 '06 #3

P: n/a
Jon Shemitz <jo*@midnightbeach.com> wrote:
"Jon Skeet [C# MVP]" wrote:
I'm not seeing the problem you are in a test program with other names.
Here's my code:


[Most of sample snipped]
global::System.String foo = "hello";


// But while you can NOT say
// global.System.String foo = "hello";


No - because global isn't a namespace, it's an alias.
Lib::Foo.Bar.Baz.SayHi();


// You CAN say
// Lib.Foo.Bar.Baz.SayHi();


Eek - that surprises me. That surprises me a *lot*. I suspect it's a
bug in the compiler, but I'll have to check the specs.

<snip>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 17 '06 #4

P: n/a
"Jon Skeet [C# MVP]" wrote:
// You CAN say
// Lib.Foo.Bar.Baz.SayHi();


Eek - that surprises me. That surprises me a *lot*. I suspect it's a
bug in the compiler, but I'll have to check the specs.


That'd be cool. What would you check? Aliases and the :: operator are
not in my printed copy of "The C# Programing Language" nor are they in
the online Word doc.

Would the [Lovely. Clear. Not!] ECMA spec be the place to go?

--
<http://www.midnightbeach.com>
Jan 17 '06 #5

P: n/a
Jon Shemitz <jo*@midnightbeach.com> wrote:
"Jon Skeet [C# MVP]" wrote:
// You CAN say
// Lib.Foo.Bar.Baz.SayHi();


Eek - that surprises me. That surprises me a *lot*. I suspect it's a
bug in the compiler, but I'll have to check the specs.


That'd be cool. What would you check? Aliases and the :: operator are
not in my printed copy of "The C# Programing Language" nor are they in
the online Word doc.

Would the [Lovely. Clear. Not!] ECMA spec be the place to go?


Yup, the ECMA spec it is. It's still in draft form. It's not *hugely*
easy to read, but it's not bad when you get into it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.