vendredi 2 janvier 2015

Getproperties in the result of reflection invoke

I have following code in reflection was trying to get the PropertyInfo and value returned


EDIT: GetObject has been used to get the object of already initialized value .


EDIT: missed the line



object valDefault = mInfo.Invoke(objNewcompact, objParams);
if (valDefault.GetType().IsGenericType && valDefault.GetType().GetGenericTypeDefinition() == typeof(List<>))
{
PropertyInfo[] propertyInfo = valDefault.GetType().UnderlyingSystemType.GetGenericArguments()[0].GetProperties();

//Activator.GetObject(valDefault.GetType().UnderlyingSystemType.GetGenericArguments()[0].UnderlyingSystemType, "http://localhost:8000/" + valDefault.GetType().UnderlyingSystemType.GetGenericArguments()[0].UnderlyingSystemType);
string ResultString = string.Empty;
object ooo = Activator.GetObject(valDefault.GetType().UnderlyingSystemType.GetGenericArguments()[0].UnderlyingSystemType, null);

for (int j = 0; j < propertyInfo.Count(); j++)
{
ResultString += propertyInfo[j].GetValue(valDefault.GetType().UnderlyingSystemType.GetGenericArguments()[0].UnderlyingSystemType, null);
}


I know there has been a confusing variable name. All I need value from the property from that PropertyInfo.






Aucun commentaire:

Enregistrer un commentaire