namespace problem

  • Thread starter Thread starter Steven Wolf
  • Start date Start date
S

Steven Wolf

hi again,

i have several namespacing problems in my big project.

my current namespaces in my solution are:

b2b.Server.Common
b2b.Server.Business
b2b.Server.Business.Mapping
b2b.Server.Business.Entities
b2b.Server.Database



now i have a testing app and i include all of those namespaces in that
app.


Server.Business.Mapping.Facility facility = new
Server.Business.Mapping();

works, but:

Business.Mapping.Facility facility...

or

Mapping.Facility facility...

doesnt work!! of course i have references to those librarys because i
can find them when i begin from Server... but not when i beging from
Business.. why?!
i never had those problems in VB.NET, only in c#..

thanks
Steve.
 
Steven Wolf said:
i have several namespacing problems in my big project.

my current namespaces in my solution are:

b2b.Server.Common
b2b.Server.Business
b2b.Server.Business.Mapping
b2b.Server.Business.Entities
b2b.Server.Database

now i have a testing app and i include all of those namespaces in that
app.


Server.Business.Mapping.Facility facility = new
Server.Business.Mapping();

Hang on - is Mapping a class as well as a namespace, or did you mean to
write new Server.Business.Mapping.Facility()?
works, but:

Business.Mapping.Facility facility...

or

Mapping.Facility facility...

doesnt work!! of course i have references to those librarys because i
can find them when i begin from Server... but not when i beging from
Business.. why?!

Because namespaces aren't treated in that way in C# - types in the
hierarchy "above" the declaring namespace are automatically included,
but the declaring namespace doesn't become a sort of "root".

Fortunately, with using declarations it shouldn't be a problem - just
declare

using Server.Business.Mapping;

at the top of your class.
i never had those problems in VB.NET, only in c#..

Indeed, C# doesn't treat namespaces in quite the same way as VB.NET.
 
Hi Jon


Hang on - is Mapping a class as well as a namespace, or did you mean to
write new Server.Business.Mapping.Facility()?

No, Mapping is a namespace of b2b.Server.Business and Facility is a
class there.

I map there DataTables to my domain objects.

Fortunately, with using declarations it shouldn't be a problem - just
declare

using Server.Business.Mapping;

at the top of your class.


Well, the problem is, i have also a Facility class in
Server.Business.Entities, so i must use for example

Entities.Facility facility = new Entities.Facility();
Mapping.Facility facilityMapper = new Mapping.Facility();

and so on. but with declaring "using b2b.Server.Business", those both
namespaces (Entities and Mapping) don't appear..

Steve.
 
Steven Wolf said:
No, Mapping is a namespace of b2b.Server.Business and Facility is a
class there.

I map there DataTables to my domain objects.

So you did mean to write new Server.Business.Mapping.Facility, right?
Well, the problem is, i have also a Facility class in
Server.Business.Entities, so i must use for example

Entities.Facility facility = new Entities.Facility();
Mapping.Facility facilityMapper = new Mapping.Facility();

and so on. but with declaring "using b2b.Server.Business", those both
namespaces (Entities and Mapping) don't appear..

You could write

using EntitiesFacility = b2b.Server.Business.Entities.Facility;
using MappingFacility = b2b.Server.Business.Mapping.Facility;

and then use "EntitiesFacility" and "MappingFacility" everywhere.

To be honest, I'd just change one set of class names - using the same
classnames in two different namespaces which are both likely to be used
in the same class is just asking for confusion.
 
So you did mean to write new Server.Business.Mapping.Facility, right?

yes, exactly.
You could write

using EntitiesFacility = b2b.Server.Business.Entities.Facility;
using MappingFacility = b2b.Server.Business.Mapping.Facility;

and then use "EntitiesFacility" and "MappingFacility" everywhere.

wow, i never heard of that possibility, and thats exactly what i need,
thanks!
To be honest, I'd just change one set of class names - using the same
classnames in two different namespaces which are both likely to be used
in the same class is just asking for confusion.

yes, you are right, but i tried to keep the same mapper-class name as
the entity to map. I have also a b2b.Server.Database.Facility class,
it is similar to the datatable and represent a persistence object.

when i create an instance of them, i use faciltiyTable,
facilityEntity, facilityMapper and so on....

but anyway,
thank you for support.

Steven.
 
Steven Wolf said:
wow, i never heard of that possibility, and thats exactly what i need,
thanks!
Goodo.


yes, you are right, but i tried to keep the same mapper-class name as
the entity to map. I have also a b2b.Server.Database.Facility class,
it is similar to the datatable and represent a persistence object.

when i create an instance of them, i use faciltiyTable,
facilityEntity, facilityMapper and so on....

Hmm... I still think you're liable to make things more confusing than
they need to be, but that's your choice - at least now you know how you
can do it!
 
Back
Top