1

プロパティのタイプがList(of T)であるかどうかを確認できる必要がありますが、現在は確認できません。私が行った場合

TypeOf (UpdateTo.GetType.GetProperty(node.Name)) Is System.Collections.Generic.List(Of Object)

次のエラーが発生します

TypeOf(UpdateTo.GetType.GetProperty(node.Name))Is System.Collections.Generic.List(Of Object)タイプ'System.Reflection.PropertyInfo'の式をタイプ'System.Collections.Generic.List(Of物体)'。

If xmlRequestNode IsNot Nothing Then

                'if there is at least one property to update
                If xmlRequestNode.ChildNodes.Count > 0 Then

                    'loop through each property that needs setting
                    For Each node As XmlNode In xmlRequestNode.ChildNodes

                        Try

                            'TODO: We do not want to set lists of objects. Currently we have issues where it tries to set the whole object instead of 
                            'going into the object and set each property. 
                            If UpdateTo.GetType.GetProperty(node.Name).GetType() IsNot GetType(System.Collections.Generic.List(Of Object)) Then

                                'and set it to the equivalent property on the user group model that was passed in (we don't use the node value as it would need casting and could be an object)
                                UpdateTo.GetType.GetProperty(node.Name).SetValue(UpdateTo, UpdateFrom.GetType.GetProperty(node.Name).GetValue(UpdateFrom, Nothing), Nothing)

                            End If

                        Catch ex As Exception

                            'and send details of the problem
                            Return "Could not find or set a property called " & node.Name

                        End Try

                    Next

                Else

                    'and send details of the problem
                    Return "No updates were requested"

                End If

            Else

                'and send details of the problem
                Return "No object to update from was supplied"

            End If
4

1 に答える 1

2

まず、UpdateTo.GetType.GetProperty(node.Name).GetType()常にを返しますPropertyInfo。私はあなたが意味すると思いますUpdateTo.GetType.GetProperty(node.Name).GetPropertyType()か?

第二にList(of T)、タイプではありません。List(of String)は型ですが、のサブクラスではありませんList(of Object)。特定のタイプが何らかの種類であるかどうかを知る簡単な方法はありませんList(of T)。たぶん、プロパティのタイプがを実装しているかどうかを単にテストする必要がありますIList

于 2012-04-10T10:19:46.647 に答える