Name of Variable at Runtime

  • Thread starter Thread starter S Shulman
  • Start date Start date
S

S Shulman

Hi

Is there any way of finding out the name of a variable at Runtime?

I am working on solution to add all member variables of a class to a
collection and write them to file in pairs of name=value, that will save the
need to modify the file read/write method each time I add a member variable
to the class as well as ther initial code

The only other way is to use class object or add an extra member to the
collection for each memeber in the correct order

Thank you,
Shmuel Shulman
 
S Shulman said:
Is there any way of finding out the name of a variable at Runtime?

I am working on solution to add all member variables of a class to a
collection and write them to file in pairs of name=value, that will save
the need to modify the file read/write method each time I add a member
variable to the class as well as ther initial code

\\\
Imports System.Reflection
Imports System.Reflection.BindingFlags
Imports System.Reflection.MemberTypes
..
..
..
Dim typ As Type = GetType(Form1)
For Each fi As FieldInfo In typ.GetFields(Instance Or NonPublic)
Dim Value As Object = fi.GetValue(Me)
Dim s As String
Try
s = Value.ToString()
Catch ex As Exception
s = ""
End Try
MsgBox(fi.Name & " = " & s)
Next fi
///
 
S Shulman said:
Hi

Is there any way of finding out the name of a variable at Runtime?

I am working on solution to add all member variables of a class to a
collection and write them to file in pairs of name=value, that will
save the need to modify the file read/write method each time I add a
member
variable to the class as well as ther initial code

The only other way is to use class object or add an extra member to
the collection for each memeber in the correct order

http://msdn.microsoft.com/library/e...veringtypeinformationatruntime.asp?frame=true

http://msdn.microsoft.com/library/en-us/cpguide/html/cpovrserializingobjects.asp?frame=true

Armin
 

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

Back
Top