Using Enumerated Values to Access Property Collection

  • Thread starter Thread starter Gos
  • Start date Start date
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
 
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
 
Back
Top