jeudi 9 avril 2015

Should I extract this code out into methods?

I am using reflection to get some values and then pass that to an object property.


Should I refactor this out into a few methods? If so, should I refactor it out for each call. A Type, A property etc.



//base item
var item = aItem;

//The type of the item
var type = item.GetType();

//The property -- In this example a list of strings -- can be list<int> etc.
var property = type.GetProperty("Strings");

//The type of the property
var propertyType = property.PropertyType;

//Value to be converted value is a object
var value = property.GetValue(item);

//New value changing type -- Was showing a list of list -- Was using this when i had a List<object>
//var newValue = Convert.ChangeType(value, propertyType);

//The object property
ListData = value;





Aucun commentaire:

Enregistrer un commentaire