473,785 Members | 3,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confusion over namespaces

Hello,

I have a solution with two projects.

One of the projects is called MyProj with a root namespace called
MyProj.Obj.

The single source (vb) file for MyProj has a class called Obj. There is no
enclosing namespace, i.e. the class declaration is at the top of the file.

The second project is called MyProjUser and has a reference to MyProj.

The single source file for MyProjUser has the following imports statement:

Imports MyProj.Obj

Then I have a statement further down in MyProjUser like this:

Dim o as Obj

But the compiler doesn't like it. It says that Obj isn't defined.

The compiler is happier when I either have this Imports statement:

Imports MyProj.Obj.Obj

or with this statement in code:

Dim o as Obj.Obj.

What's happening here? I thought that once I imported the namespace (in this
case MyObj.Obj), then all classes in that namespace (including Obj) should
be usable without further qualification.

Or is the fact that part of the namespace and the class name are the same
(i.e. Obj) causing confusion?

TIA for any answers.

--
Akin

aknak at aksoto dot idps dot co dot uk
May 16 '06 #1
1 1152
Think of namespaces and objects as files and directories on your harddrive

your namespace is akin to c:\myproj\obj
and inside that you have created a file called obj.

in order to access your file, you must specify its full path
c:\myproj\obj\o bj

a way that I use namespaces is to break the assemblies into thought areas,
i.e

mycompany.mypro ject.

data libraries would go into mycompany.mypro ject.datalib
graphic libraries into mycompany.mypro ject..graphics
UI components into mycompany.mypro ject and
mycompany.mypro ject.customcont rols.

Additionally, when I create an assembly with a sepreate namespace it is
generally because the project itself can potentially be reused by other
assemblies without modification, otherwise, the code would all live with the
executing assembly.

for example

Our encryption library is mycompany.encry ption
Our xml, adodbo, and csv wrappers live in mycompany.data
Our generic containers such as sorted bindinglist(of T) live in
mycompany.gener ics
Our login UI components, security model all live in mycompany.secur ity and
mycompany.secur ity.ui

Finally, we then reference these libraries when designing an application

Accounting package base namespace is mycompany.accpa c

imports mycompany.accpa c
imports gencol = mycompany.gener ics

UI components import
imports mycompany.accpa c.business
imports mycompany.accpa c.UI

Business Objects import
imports mycompany.accpa c.data
imports db = mycompany.data
imports enc = mycompany.encry ption
imports sec = mycompany.secur ity

add system references (i.e. xml, data, text, collections) as appropriate

"Epetruk" <no****@blackho le.com> wrote in message
news:4c******** *****@individua l.net...
Hello,

I have a solution with two projects.

One of the projects is called MyProj with a root namespace called
MyProj.Obj.

The single source (vb) file for MyProj has a class called Obj. There is no
enclosing namespace, i.e. the class declaration is at the top of the file.

The second project is called MyProjUser and has a reference to MyProj.

The single source file for MyProjUser has the following imports statement:

Imports MyProj.Obj

Then I have a statement further down in MyProjUser like this:

Dim o as Obj

But the compiler doesn't like it. It says that Obj isn't defined.

The compiler is happier when I either have this Imports statement:

Imports MyProj.Obj.Obj

or with this statement in code:

Dim o as Obj.Obj.

What's happening here? I thought that once I imported the namespace (in
this
case MyObj.Obj), then all classes in that namespace (including Obj) should
be usable without further qualification.

Or is the fact that part of the namespace and the class name are the same
(i.e. Obj) causing confusion?

TIA for any answers.

--
Akin

aknak at aksoto dot idps dot co dot uk

May 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
3051
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
11
1792
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I understand that you declare your intention to use a namespace within a page through the "Inherits" attribute. I know that using "Inherits" isn't absolutely necessary, it's just recommended so the developer doesn't have to type out the entire...
9
1321
by: Buz Waitz | last post by:
I'm a newbie. I've created a datalayer class which I creatively called sqlAccess and placed in a namespace I just as creatively called MyDomain.DataAccessLayer. (Well now, I didn't actually use "MyDomain" but you know how that works.) And now I'm working on the business logic layer. When I import the namespace, intellisense completes the name for me, accurately, but then I get the squiggle of death that says, when I mouse over it,...
4
2662
by: Ranginald | last post by:
Sorry for the simple question but thanks in advance: My goal is to create reusale code for a web app in C#. I have written the code already as a windows app but here is where I am confused: To keep it really easy let's say this is the code: function addition(int, int); int X;
6
2262
by: vivekian | last post by:
Hi, I am not sure if this is a relevant topic here, anyways, When using the std namespace is it a good practice to .. put this right at the beginning using namespace std ;
2
2042
by: shaun roe | last post by:
I'm trying to follow the recommendations for svg writing at http://jwatt.org/svg/authoring/ and I am generating my svg with xslt. I had some problem with namespaces, and although I think I solved it, I don't really understand how. My first try at writing svg introduced the svg with <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="600px" height="400px" viewBox="-10 -10 620 420">
8
1063
by: tshad | last post by:
Using VS 2008, I have a project that uses the dll from another project. The Namespace is MyFunctions, with a class of DbObject. The beginning of the code is: *************************** Imports System Imports System.Data Imports System.Data.SqlClient Namespace MyFunctions
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.