Determine full name of an object at runtime.

G

Guest

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
 
A

Armin Zingler

Lance said:
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.

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
 
G

Guest

Thanks for the info
What's your intention? I'm sure we'll find a solution

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
 
P

Peter Huang

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top