假设我有这些课程
Public Class Connection
Private a as Node
Private b as Node
Public Property Self as Node
Public Property Other as Node
Public Sub New(a as Node, b as Node)
Me.a = a : Me.b = b
a.Connection = Me : b.Connection = Me
End Sub
End Class
Public Class Node
Public Connection as Connection
End Class
我就这样设置了
Dim a = New Node()
Dim b = New Node()
Dim c = New Connection(a, b);
因此两个节点共享同一个Connection对象。现在我想弄清楚是否有可能为Connection属性Self和Other定义一个getter,它可以检测到他们正在访问哪个对象并相应地改变它们的返回值?
例如一些伪代码
Public Property Other as Node
Get
If (<CalledThroughObject> = a) Then Return b
Return a
End Get
这应该是结果
a.Connection.Other = b
b.Connection.Other = a