因为三个是只读的并且取决于非属性(四个)。三个应该是不确定的 道具如何设置四个,将三个设置为正确值?
public sub main
Dim x1 = New one, x2 = New two
x1.one = 3
MoveCorresponding(x1, x2)
end sub
Public Sub MoveCorresponding(a As Object, b As Object, Optional ignoreList As List(Of String) = Nothing)
Dim oType As Type = b.GetType
Dim iType = a.GetType
Dim props = iType.GetProperties()
For Each pInf As PropertyInfo In props
Dim parName = pInf.Name
If pInf.CanWrite Then
Try
Dim val = pInf.GetValue(a, Nothing)
pInf.SetValue(b, val)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Next
End Sub
End Class
Class one
Public Property one As String = "1"
Dim four As Integer = 1
Public ReadOnly Property three As Integer
Get
Return four * 10
End Get
End Property
End Class
答案 0 :(得分:1)
您在声明它的同一行设置four
:
Dim four As Integer = 1 '<-- see? it's set to "1".
属性three
只是从four
:
Return four * 10
我不理解你的问题吗?
答案 1 :(得分:-1)
这不是回答这个问题。 但为什么要编写这样的代码?
令人困惑。
dim four as integer = 1 ' <=== But why? Why use four as object name but hold 1 as it's value??