dimanche 3 avril 2016

vb.net reflection.propertyinfo for lists and Sortedlists and objects

I have a class of pubic properties as String, Boolean, double SortedList(Of String, String) SortedList(Of Int16, String), SortedList(Of Int16, object), List(Of object)and double. I am able use
System.Reflection.PropertyInfo where Dim pInfo As System.Reflection.PropertyInfo = obj.GetType.GetProperty(propertyName) where propertyName is a string. Then I convert the value (_property.Value) to the type of the Property to which it will be assigned. CTypeDynamic must be used so that thetype retrieved from pInfo can be used.

tmpVal = CTypeDynamic(_property.Value, pInfo.PropertyType)

Use the PropertyInfo to set the value of the property that matches nme. pInfo.SetValue(obj, tmpVal) where

Dim tmpVal As Object = Nothing

If the property is an non array such as a boolean, string, and double it will reflect properly, but for lists or sortedlists I do not know how to reflect the array of values. Any help would be great and thank you ahead of time.





Aucun commentaire:

Enregistrer un commentaire