0

我正在尝试动态创建对象和/或属性...这可能吗?

CLIENT_INFO
  NAME
    F_NAME (= "LoriBeth")
    L_NAME (= "Johnson")
  ADDRESS
    ADDY1 (= "123 MyStreet")
    ETC (= "Etc")

在哪里:

Dim objCreated as Object
Dim objName AS String = "CLIENT_INFO"
Dim 1stProp as String = "NAME"
etc...

objCreated = makeObject(objName, objProp1, etc...)

Function makeObject(byval objName as String, byval objProp1 as String, etc...)
  Class &objName
    Property &objProp1
    End Property
  End Class

  Return &objName
End Function

(我使用 VFP 方式在运行时将 vars 替换为它们的值)

最终得到一个可寻址的对象,例如:

CLIENT_INFO.NAME.F_NAME = "LoriBeth"

4

2 回答 2

0

You can create a single property typed as a Dictionary(Of String, Object) to accomplish your expando- functionality.

But this whole thing seems like a really bad idea.

于 2012-07-23T18:24:55.663 回答
0

汉斯,这很酷,很高兴知道,但不允许我做我第一次发布的内容。即使是这样的事情也会更有帮助:

Option Strict Off 
Imports System.Dynamic  
Module Module1     
   Sub Main()         
      Dim OldBag As Object = New ExpandoObject         
      OldBag.Name = "Hans"         
      OldBag.Age = 21         
      OldBag.NewName = "NewBag"
      Console.WriteLine(NewBag.Name)         
      Console.WriteLine(NewBag.Age)
   End Sub 
End Module 
于 2012-07-27T19:04:55.390 回答