J
jw56578
Im trying to use FieldInfo.SetValue to set the values of fields in a
class, the class is using reflection on itself to popluate its own
fields. but i keep getting this error.
Object type cannot be converted to target type
here is code
Dim myFieldInfo() As System.Reflection.FieldInfo
Dim myType As Type = Me.GetType
' Get the type and fields of FieldInfoClass.
myFieldInfo =
myType.GetFields(Reflection.BindingFlags.NonPublic Or _
Reflection.BindingFlags.Instance Or
Reflection.BindingFlags.Public)
' Display the field information of FieldInfoClass.
Dim i As Integer
For i = 0 To myFieldInfo.Length - 1
Dim customatts() As Object =
myFieldInfo(i).GetCustomAttributes(True)
If customatts.Length > 0 Then
Dim fm As FieldMember = CType(customatts(0),
FieldMember)
If htFields.Contains(fm.DbFieldName) Then
myFieldInfo(i).SetValue(me, htFields(fm.DbFieldName))
End If
Next i
the error occurs on SetValue
class, the class is using reflection on itself to popluate its own
fields. but i keep getting this error.
Object type cannot be converted to target type
here is code
Dim myFieldInfo() As System.Reflection.FieldInfo
Dim myType As Type = Me.GetType
' Get the type and fields of FieldInfoClass.
myFieldInfo =
myType.GetFields(Reflection.BindingFlags.NonPublic Or _
Reflection.BindingFlags.Instance Or
Reflection.BindingFlags.Public)
' Display the field information of FieldInfoClass.
Dim i As Integer
For i = 0 To myFieldInfo.Length - 1
Dim customatts() As Object =
myFieldInfo(i).GetCustomAttributes(True)
If customatts.Length > 0 Then
Dim fm As FieldMember = CType(customatts(0),
FieldMember)
If htFields.Contains(fm.DbFieldName) Then
myFieldInfo(i).SetValue(me, htFields(fm.DbFieldName))
End If
Next i
the error occurs on SetValue