获取my.settings中项目的“名称”

时间:2017-09-27 15:32:39

标签: vb.net

我想要一个my.settingings.count的名称,而不是值。示例如下:

Dim bind()() As Object = {
  New Object() {"countForward"},
  New Object() {"countInstalls"},
  New Object() {"countKeys"},
  New Object() {"countUpgrade"}}

For Each ary In bind
  My.Settings(CStr(ary.First)) = "0"
Next

我想要的是与此类似的东西:

Dim bind()() As Object = {
  New Object() {my.settings.countForward.name},
  New Object() {my.settings.countInstalls.name},
  New Object() {my.settings.countKeys.name},
  New Object() {my.settings.countUpgrade.name}}

谢谢桑迪

2 个答案:

答案 0 :(得分:1)

您可以使用Reflection

实现此目的
' get properties whose names contain "count"
' return as object arrays

Dim bind()() As Object =
    My.Settings.
    GetType().
    GetProperties().
    Where(Function(p) p.Name.Contains("count")).
    Select(Function(p) New Object() {p.Name}).
    ToArray()

修改

我做了更多的挖掘,你根本不需要反思。有一个名为Properties的属性,它只返回用户属性。

Dim bind()() As Object =
    My.Settings.Properties.
    OfType(Of Configuration.SettingsProperty).
    Select(Function(p) New Object() {p.Name}).
    ToArray()

答案 1 :(得分:0)

CallByName(我的设置,nameOfProperty,Microsoft.VisualBasic.CallType.Get,什么都没有)