|
-
Jan 12th, 2010, 10:28 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Jan 12th, 2010, 10:46 AM
#2
Re: Namespace Resolution
Code:
Dim foobar As New foo
foobar.bar=?
Class foo
Class bar
End Class
End Class
-
Jan 12th, 2010, 10:52 AM
#3
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
-
Jan 12th, 2010, 11:17 AM
#4
Thread Starter
Hyperactive Member
Re: Namespace Resolution
totally agree, but anyway i was just trying to solve the problem. its something like this:
vb.net Code:
Namespace LIBB Public Class Class1 Dim a As LIBB.Class2 '<-- Undefined Public Class LIBB End Class Public Class Class2 End Class End Class Public Class Class2 ' <-- I cannot access this class End Class End Namespace
-
Jan 12th, 2010, 11:24 AM
#5
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
 
-
Jan 13th, 2010, 11:03 AM
#6
Thread Starter
Hyperactive Member
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
-
Jan 13th, 2010, 12:00 PM
#7
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
 
-
Jan 13th, 2010, 12:18 PM
#8
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
-
Jan 13th, 2010, 01:59 PM
#9
Thread Starter
Hyperactive Member
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:
Namespace MyLibrary
Namespace System
Namespace Windows
Namespace Forms
End Namespace
End Namespace
Public Class [Enum]
End Class
Public Class Math
End Class
End Namespace
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.
-
Jan 13th, 2010, 02:15 PM
#10
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
 
-
Jan 13th, 2010, 03:25 PM
#11
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
-
Jan 13th, 2010, 03:38 PM
#12
Thread Starter
Hyperactive Member
Re: Namespace Resolution
dat's something cool, thanks = )
-
Jan 13th, 2010, 03:51 PM
#13
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|