read name of property during runtime

P

Peter Gast

Hi,
I need as a parameter for a control the names of my properties as a string.
How can I get the name of the property as a string during runtime

Example:
Private _MyVar As Double
Public ReadOnly Property MyVar As Double
Get
Return _MyVar
End Get
End Property

.....
MsgBox ( ???? MyVar.GetType ?????)
.....


The result should be "MyVar", I've got a tip to us Type.GetField(...), but
this expressions doesn't work.


Thanks Peter
 
A

Armin Zingler

Peter Gast said:
Hi,
I need as a parameter for a control the names of my properties as a
string. How can I get the name of the property as a string during
runtime

Example:
Private _MyVar As Double
Public ReadOnly Property MyVar As Double
Get
Return _MyVar
End Get
End Property

....
MsgBox ( ???? MyVar.GetType ?????)
....


The result should be "MyVar", I've got a tip to us
Type.GetField(...), but this expressions doesn't work.


Why do you need the name of a property? This does not make sense at all: If
you need the name of a property, you must know the name of which property to
get the name. That's...

I you want to get the name of all properties of a class, use
Type.GetProperties.

Do you want to get the /type/ of the property?

Maybe you are looking for the /value/ of an object's property while late
binding the property's name? Then Type.GetField should work.


"/Advanced/ Development Technologies":
http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx



Armin
 
P

Peter Gast

Hi Armin,
I have a 3rd party control and the parameters has to be given like this (for
ex.)
prp = ctl.AppendProperty(Parent, id , "The value is", Me, "MyVar", "Here is
the comment to MyVar")
"The value is": This is displayed in the left column of a grid
Me: The class where the Property is a memher of
"MyVar": The property MyVar (Has to be written as a string, that
prevents unfortunately this parameter that it can be renamed automaticly by
IDE)

The value of the property is shown in the right col of the grid. I'm
wondering why a parameter is given such a way, but it is and I should have a
solution which "extract" the NAME of the variable to a string. I hope I've
explained it clear enough. Beside I'm not looking for the value of the
property.

I have still problems to use the suggested Type.GetField(..), Where I have
to write MyVar in this method? Can you give me the whole syntax, ideal with
the example MyVar? When I rename MyVar in the IDE the rename should be
appear in this expressions too.

Thanks Peter
 
A

Armin Zingler

Peter Gast said:
Hi Armin,
I have a 3rd party control and the parameters has to be given like
this (for ex.)
prp = ctl.AppendProperty(Parent, id , "The value is", Me, "MyVar",
"Here is the comment to MyVar")
"The value is": This is displayed in the left column of a grid
Me: The class where the Property is a memher of
"MyVar": The property MyVar (Has to be written as a string, that
prevents unfortunately this parameter that it can be renamed
automaticly by IDE)

The value of the property is shown in the right col of the grid. I'm
wondering why a parameter is given such a way, but it is and I
should have a solution which "extract" the NAME of the variable to a
string. I hope I've explained it clear enough. Beside I'm not
looking for the value of the property.

I have still problems to use the suggested Type.GetField(..), Where
I have to write MyVar in this method? Can you give me the whole
syntax, ideal with the example MyVar? When I rename MyVar in the IDE
the rename should be appear in this expressions too.

Thanks Peter


I see now what you're trying, but I think it is not possible. If you rename
MyVar, you manually have to change the string "MyVar", too. The IDE has no
relation between the two. I don't see a way to do it because the 3rd party
control seems to always need a string, and as long as you need a string you
will always have to change the string manually.

In other words, there is no compiler support like "GetName(MyVar)".


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

Top