我有一些像这样排列的嵌套对象:
所以你有一个过程。然后可以添加多个人,也可以添加多个WorkFlow。可以将多个任务添加到每个WorkFlow,但我需要一种方法来管理哪个Person正在执行每项任务。我基本上需要一种方法,为每个Person添加到Process中,在它的构造函数中,分配一个Person.ID属性,然后可以将其分配到每个Task的PersonID属性中......
Dim myProcess as New Process()
Dim myPerson as New Process.Person()
myProcess.AddPerson(myPerson)
Dim myWorkFlow as New Process.WorkFlow()
Dim myTask as New Process.WorkFlow.Task()
myTask.PersonID = myPerson.ID '<--- AutoID was populated as soon as myPerson was created
myWorkFlow.AddTask(myTask)
myProcess.AddWorkFlow(myWorkFlow)
以下是一些伪代码的PasteBin:http://pastebin.com/0r9rnUjz
答案 0 :(得分:1)
您可以在Person类中使用一些共享变量,这样对于每个创建的新实例,它将从该计数器获取一个新的id,如下例所示。
Public Class Person
Private incrementedID As Integer = 0
Public ReadOnly Property ID As Integer
Get
Return Me.incrementedID
End Get
End Property
Private Shared nextId As Integer = 0
Public Sub New()
Me.incrementedID = System.Threading.Interlocked.Increment(nextId)
End Sub
End Class
答案 1 :(得分:0)
我使用了Guid而不是像Chris Haas在评论中所建议的那样。