My.Settings object set setting by name?

  • Thread starter Dachshund Digital
  • Start date
D

Dachshund Digital

I know there must be a way to do this... in .NET 2.0?

I have a situation where I know the name of the setting, and want to
pass it into a function, and set or get the corresponding setting.

The following is find, but a pain if you have lots of settings to do in
one go...

My.Setting.Dachshund=1000
Dim theSetting As Integer=My.Setting.Dachshund

Looking for some thing like...

Sub SetSetting(ByVal theName As String, ByVal theValue As Object)

My.Setting(theName) = theValue

End Sub

Function GetSetting(ByVal theName As String) As Object

Return (My.Settings(theName))

End Function

I figure i could call My.Setting.<Method>? Via Invoke by name? But I
am not a Invoke guru?

Any help greatly desired, Thanks
 
D

david

I know there must be a way to do this... in .NET 2.0?

I have a situation where I know the name of the setting, and want to
pass it into a function, and set or get the corresponding setting.

The following is find, but a pain if you have lots of settings to do in
one go...

My.Setting.Dachshund=1000
Dim theSetting As Integer=My.Setting.Dachshund

Looking for some thing like...

Sub SetSetting(ByVal theName As String, ByVal theValue As Object)

My.Setting(theName) = theValue

This is evil, but you could always do something like

My.MySettingsProperty.Settings.Item(theName) = value


Rather than using undocumented names though, you'd probably be better
off saving a hashtable or NameValueCollection in My.Settings, then
accessing its members normally.
 

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