Connecting Tech Pros Worldwide Forums | Help | Site Map

Determine full name of an object at runtime.

Lance
Guest
 
Posts: n/a
#1: Nov 20 '05
Is there any way to determine the full name of an object at runtime? For example, if I have the following

Namespace MyNameSpac
Public Class MyClas
Protected MyObject As Object 'This could be any type
End Clas
End Namespac

then I want a function that would return the string, "RootNamespace.MyNameSpace.MyClass.MyObject" if I passed MyObject to the function, where RootNamespace is the root namespace for the project

Thanks for any help
Lanc


Armin Zingler
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Determine full name of an object at runtime.


"Lance" <zippy@hotmail.com> schrieb[color=blue]
> Is there any way to determine the full name of an object at runtime?
> For example, if I have the following:
>
> Namespace MyNameSpace
> Public Class MyClass
> Protected MyObject As Object 'This could be any type.
> End Class
> End Namespace
>
> then I want a function that would return the string,
> "RootNamespace.MyNameSpace.MyClass.MyObject" if I passed MyObject to
> the function, where RootNamespace is the root namespace for the
> project.[/color]

This is not possible. If you pass a reference to a function, the function
can not know where the reference was stored. Even if you'd pass it ByRef,
the function won't know of which object and which class and namespace the
referenced variable is part of.

What's your intention? I'm sure we'll find a solution.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Armin Zingler
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Determine full name of an object at runtime.


"Lance" <zippy@hotmail.com> schrieb[color=blue]
> Is there any way to determine the full name of an object at runtime?
> For example, if I have the following:
>
> Namespace MyNameSpace
> Public Class MyClass
> Protected MyObject As Object 'This could be any type.
> End Class
> End Namespace
>
> then I want a function that would return the string,
> "RootNamespace.MyNameSpace.MyClass.MyObject" if I passed MyObject to
> the function, where RootNamespace is the root namespace for the
> project.[/color]

This is not possible. If you pass a reference to a function, the function
can not know where the reference was stored. Even if you'd pass it ByRef,
the function won't know of which object and which class and namespace the
referenced variable is part of.

What's your intention? I'm sure we'll find a solution.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Lance
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Determine full name of an object at runtime.


Thanks for the info
[color=blue]
>What's your intention? I'm sure we'll find a solution[/color]

Having this feature would have allowed me to automate a part of my app, but implementing a work around is not difficult

Thanks again for your help
Lance
Lance
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Determine full name of an object at runtime.


Thanks for the info
[color=blue]
>What's your intention? I'm sure we'll find a solution[/color]

Having this feature would have allowed me to automate a part of my app, but implementing a work around is not difficult

Thanks again for your help
Lance
Peter Huang
Guest
 
Posts: n/a
#6: Nov 20 '05

re: Determine full name of an object at runtime.


Hi Lance,

I agree with Armin's suggestion. When we pass an object, we will not know
what class the object belong to, we have to do it ourself.

For a workaroud, You may try to pass the TestABC object in the meantime, so
that we know that.

e.g.
[TestCls]
Public Class TestABC
Public tls As ArrayList
Public tls2 As ArrayList
Public Shared Function Hello() As String
Return "Hello World"
End Function
End Class

[Module1.vb]
Dim o As New TestCls.TestABC
o.tls2 = New ArrayList
Dim c As Object
c = o.tls2
Console.WriteLine(o.GetType().ToString)
For Each b As System.Reflection.FieldInfo In o.GetType().GetFields()
If Object.ReferenceEquals(c, b.GetValue(o)) Then
Console.WriteLine(b.Name)
End If
Next
Console.WriteLine(o.Hello)




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Peter Huang
Guest
 
Posts: n/a
#7: Nov 20 '05

re: Determine full name of an object at runtime.


Hi Lance,

I agree with Armin's suggestion. When we pass an object, we will not know
what class the object belong to, we have to do it ourself.

For a workaroud, You may try to pass the TestABC object in the meantime, so
that we know that.

e.g.
[TestCls]
Public Class TestABC
Public tls As ArrayList
Public tls2 As ArrayList
Public Shared Function Hello() As String
Return "Hello World"
End Function
End Class

[Module1.vb]
Dim o As New TestCls.TestABC
o.tls2 = New ArrayList
Dim c As Object
c = o.tls2
Console.WriteLine(o.GetType().ToString)
For Each b As System.Reflection.FieldInfo In o.GetType().GetFields()
If Object.ReferenceEquals(c, b.GetValue(o)) Then
Console.WriteLine(b.Name)
End If
Next
Console.WriteLine(o.Hello)




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Armin Zingler
Guest
 
Posts: n/a
#8: Nov 20 '05

re: Determine full name of an object at runtime.


"Lance" <anonymous@discussions.microsoft.com> schrieb[color=blue]
> Thanks for the info.
>[color=green]
> >What's your intention? I'm sure we'll find a solution.[/color]
>
> Having this feature would have allowed me to automate a part of my
> app, but implementing a work around is not difficult.[/color]

Well, withouth details I can't help you any further. I hope your work around
is "better" than my/our solution would have been. ;-)


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Armin Zingler
Guest
 
Posts: n/a
#9: Nov 20 '05

re: Determine full name of an object at runtime.


"Lance" <anonymous@discussions.microsoft.com> schrieb[color=blue]
> Thanks for the info.
>[color=green]
> >What's your intention? I'm sure we'll find a solution.[/color]
>
> Having this feature would have allowed me to automate a part of my
> app, but implementing a work around is not difficult.[/color]

Well, withouth details I can't help you any further. I hope your work around
is "better" than my/our solution would have been. ;-)


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Lance
Guest
 
Posts: n/a
#10: Nov 20 '05

re: Determine full name of an object at runtime.


Great suggestion. Thanks.
Lance
Guest
 
Posts: n/a
#11: Nov 20 '05

re: Determine full name of an object at runtime.


Great suggestion. Thanks.
Closed Thread