473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Determine full name of an object at runtime.

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

Nov 20 '05 #1
10 853
"Lance" <zi***@hotmail.com> schrieb
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
Nov 20 '05 #2
"Lance" <zi***@hotmail.com> schrieb
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
Nov 20 '05 #3
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
Nov 20 '05 #4
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
Nov 20 '05 #5
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.

Nov 20 '05 #6
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.

Nov 20 '05 #7
"Lance" <an*******@discussions.microsoft.com> schrieb
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.


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

Nov 20 '05 #8
"Lance" <an*******@discussions.microsoft.com> schrieb
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.


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

Nov 20 '05 #9
Great suggestion. Thanks.
Nov 20 '05 #10
Great suggestion. Thanks.
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
18
by: Keith Brown | last post by:
I have an application that allows embedded storage of ANY chosen file in an OLE field. The file could have been dragged-and-dropped into the field or it might have been selected and imported...
3
by: nfr | last post by:
I have a Singleton Model object that can be instantiated by different applications at runtime. This object activates a Channel using the config file in its constructor, which needs the name of the...
1
by: Dan | last post by:
All, I am working on an application that allows users to track various items for various clients. For example Client A may have an object Box where Client B has an object Canister. When a user...
3
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image"...
10
by: Lance | last post by:
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...
3
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the...
6
by: William | last post by:
for example, I have a global object: extern Object myobj; Can gcc get this object by using string "myobj" at runtime?? I know C++ rtti doesnt support this, but I dont know if gcc can , ...
4
by: Bill Fuller | last post by:
I am trying to determine the type for ActiveControls using 3rd party controls (Infragistics in this case) during runtime and getting a rather odd return type at runtime for the UltraWinEditor. ...
3
by: LordHog | last post by:
Hello, How would I go about finding the default handler, let's say a text file (*.txt), then launch the default handler with the file as an argument? I had found how to launch an external...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.