473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

extern alias and dotted names

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
5 2416
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill Kratzer | last post by:
Hi... I am currently working on a Java-based product that is backed by PostgreSQL (among other databases). I have noticed that PostgreSQL appears to truncate column alias names after 31...
3
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
5
by: Santiago Ordax Solivellas | last post by:
Hi. We have almost all our tables defined on library lib1 and some on lib2. We have alias defined on lib1 to access tables on lib2 so there is no need to qualify library name. Alias for tables on...
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
0
by: Hervé | last post by:
I am referencing two different assemblies from a Visual Studio 2005 Web project. These two assemblies have the exact same type name defined (fully qualified name). This gives me a compilation...
2
by: Daniel.Peaper | last post by:
Hi folks, I'm trying to write a simple SELECT statement that will execute in query analyser but will just have the data with no column names, or the dotted line between them and the data. I also...
5
by: Steven T. Hatton | last post by:
This note appears in the discussion of name hiding and uniqueness: §3.3 #4 This note is item #6 in the discussion of "Point of declaration" §3.3.1 #6 What exactly do these statements mean?...
2
by: Brian Kendig | last post by:
I'm trying to make a web page with a restaurant menu on it. Each line on the menu is the name of a dish (left-justified) and that dish's price (right-justified), with a dotted line between them....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.