Using Enumerated Values to Access Property Collection

G

Gos

Hi,

I have an enum type as defined below. The enum constants are some of
the properties for a windows form control. I want to store the
settings for that control into a file. In order to access the value of
the properties (for example toolbar.Size or Toolbar.Name) I used a for
loop. In my for loop, I want to do something like
toolbar.[Enum](Prop.GetName)(which is equal to toolbar.Size and
returns the value into the string)

Public Enum ToolBarSettings
Name
Size
Location
End Enum

Dim Properties As Type = GetType(ToolBarSettings)
For Each Prop In [Enum].GetNames(Properties)
Dim s as string = toolbar.[Enum](Prop.GetName) ' I want
this to return toolbar.size into the string)
Next

Is there a way that I can do this?

Thank you
Gos
 
P

Patrick Steele [MVP]

gowsalya_ said:
Hi,

I have an enum type as defined below. The enum constants are some of
the properties for a windows form control. I want to store the
settings for that control into a file. In order to access the value of
the properties (for example toolbar.Size or Toolbar.Name) I used a for
loop. In my for loop, I want to do something like
toolbar.[Enum](Prop.GetName)(which is equal to toolbar.Size and
returns the value into the string)

Public Enum ToolBarSettings
Name
Size
Location
End Enum

Dim Properties As Type = GetType(ToolBarSettings)
For Each Prop In [Enum].GetNames(Properties)
Dim s as string = toolbar.[Enum](Prop.GetName) ' I want
this to return toolbar.size into the string)
Next

Is there a way that I can do this?

Use Reflection. See:

http://tinyurl.com/n0cp
 

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