Results 1 to 13 of 13

Thread: [RESOLVED] Namespace Resolution

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Resolved [RESOLVED] Namespace Resolution

    if my class library is called LIBB and within LIBB i have a class MyClass

    So within MyClass i have a member called LIBB as well. how do i refer to LIBB (class library) from anywhere within MyClass. if i'd typed LIBB it would refer to the member instead of the class library.


    No i do not have a name clash right now, i was just wondering how would it be done.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Namespace Resolution

    Code:
        Dim foobar As New foo
        foobar.bar=?
    
    Class foo
        Class bar
    
        End Class
    End Class
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Namespace Resolution

    since to get to the member, you specify the class, it's kind of moot... however... this is a good reason why naming members after types is a generally avoided practice (except in C#, which is case sensitive, so your type "IsLikeThis" and the member would be "isLikeThis").

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: Namespace Resolution

    totally agree, but anyway i was just trying to solve the problem. its something like this:

    vb.net Code:
    1. Namespace LIBB
    2.  
    3.     Public Class Class1
    4.         Dim a As LIBB.Class2 '<-- Undefined
    5.         Public Class LIBB
    6.  
    7.         End Class
    8.         Public Class Class2
    9.  
    10.         End Class
    11.     End Class
    12.  
    13.     Public Class Class2 ' <-- I cannot access this class
    14.  
    15.     End Class
    16.  
    17. End Namespace

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Namespace Resolution

    Of course not. You have two different Class2 in the same file. How would the compiler know which one you want? Just because one is defined within a different class makes no real difference in this case. One is shadowing the other.

    The bottom line is this: Name collision happens. That's one of the reasons behind having classes, and is the only reason behind having namespaces. Still, it doesn't preclude poor name choices resulting in name collisions, and there is no way around that. At some point, you have to take responsibility for naming things in ways that don't conflict. There are conventions that help restrict the possible conflicts, but you can still cause those conflicts, and when you do, you should realize that the idea is a bad one, not the language. After all, it is technically impossible to have a 'complete' language, which is one that has no invalid constructs.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: Namespace Resolution

    orh, i was hoping for something like relative positions since every member must belong to one parent just like how every file must belong to one folder. so it will be something like this:

    Code:
     Dim a As <root>.<root>.Class2

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Namespace Resolution

    Yeah, that's nearly the case. Unfortunately, declaring a public class within a class doesn't resolve the way you are hoping it would, and that prevents the construction you are trying for. Personally, I would prefer if it was done the way you were expecting, because as it is there is no justification that I can see for declaring a public class within a different class. Declaring it Private does have an impact, though.

    You could probably get something close to what you are looking at with nested namespaces, but not with nested classes.
    My usual boring signature: Nothing

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Namespace Resolution

    there is no justification that I can see for declaring a public class within a different class.
    And yet, that is exactly how types datasets are designed. The typed datatable is a class inside the typed dataset. And to get to it, I use the NS.DS.DT .... then again, we're not dealing with an inner class that has the same name as an outer class in that case.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: Namespace Resolution

    actually i first had this problem when i was trying to imitate the existing namespaces into my class library.

    So basically i had something like this:

    vb.net Code:
    1. Namespace MyLibrary
    2.     Namespace System
    3.         Namespace Windows
    4.             Namespace Forms
    5.             End Namespace
    6.         End Namespace
    7.         Public Class [Enum]
    8.         End Class
    9.         Public Class Math
    10.         End Class
    11.     End Namespace
    12. End Namespace
    and somewhere in MyLibrary.System.Math i would wish to refer to the real System.Math but couldn't find a way to do so.

    de temporary solution i had was to rename System to Sys, which of course is what i did only because i do not have a choice.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Namespace Resolution

    There is a way to alias a name. Since you have your own system, you might want to alias the actual system inside MyLibrary. I have never used aliasing, and am not sure that it is possible, but it would be something like Using System As OuterSystem, or some such.
    My usual boring signature: Nothing

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Namespace Resolution

    You can alias if you IMPORT a namespace:
    Code:
    Imports M = Namespace.Namespace2.namespace3.anothersnamespace.assembly
    Then to get to any of the classes in "M" you use M like any other namespace:
    Code:
    Dim myMClass As New M.MClass
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: Namespace Resolution

    dat's something cool, thanks = )

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Namespace Resolution

    I use it a lot when dealing with things from Infragistics, which is notorious for their endless namespacing. Some one once referred to it as the Infragistics Ultra Megazord WinGrid.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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