Results 1 to 5 of 5

Thread: [RESOLVED] Reference Default Namespace in Class

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Resolved [RESOLVED] Reference Default Namespace in Class

    Hi and thanks for reading.

    I'm trying to develop a generic class that uses Imports statements. Right now, the Imports reference the name of a specific project (e.g. "Imports WWRIS.DataAccessLayer" and "Imports WWRIS.Global"), I want to eliminate the "WWRIS" part to make the class truly generic (e.g. "Imports [Project Default Namespace].DataAccessLayer"). Is this possible?

    I know I could remove the namespace for a project altogether, but I would prefer not too.

    Thanks,
    OneSource

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Reference Default Namespace in Class

    You mean dynamically change the namesapce? Why would the name change? Isn't the project you are referencing going to have the same namespace?

    Instead of importing the namespaces just call all the members by the full namespace (i.e. WWRIS.DataAccessLayer.MyMethod)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question Edneeis ...

    Thanks for your response.

    You mean dynamically change the namesapce?
    Yes!

    Isn't the project you are referencing going to have the same namespace?
    Yes, but I want to use the generic class in multiple projects without having to tinker with the namespace every time. Understand?

    WWRIS.DataAccessLayer.MyMethod
    is specific to the WWRIS project. When I put the class in another project, I don't want to have to update the Import statements in the generic class, because I need to access [Project Default Namespace].DataAccessLayer.MyMethod in whatever project I place the class into.

    In short, I don't want to change the Imports statement based on the project that the generic class is used in. I just want to drop in the class and have it get the default namespace of the project and use it with the Imports statement, i.e. [Project Default Namespace].DataAccessLayer.MyMethod. Is this possible?

    Thanks...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Reference Default Namespace in Class

    I can't give you a 100% iron-clad guarantee but I'm going to say with relative surety that it is not possible, and why would it be? If you were allowed to change the namespace like that then there would be no guarantee that each would contain the same members. If you want to use that library like that then you need to set it up in such a way that it will expect certain types that all the other projects can supply. This sounds like a job for an Interface to me. That way, the generic library can take and return objects that implement certain interfaces and your other projects can implement those interfaces, allowing them all to use the other library.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    jmcilhinney ....

    Thanks. I didn't know if it was possible and feel even more so that it isn't after reading your reply. I'll look at using an Interfaces to the class.

    OneSource

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width