jeudi 26 mars 2015

asp.net C# how to get a propertyvalue for nested properties?

Hi I am trying to do the sort on a list of objects, the code in my else statements works like charm but there is a column that has nested property and that's where the problem occurs. when I try to get the value of the nested property it gives me null exception. Can you help me globalize the code so I don't have this extra if in my code? if (e.SortExpression == "Distribution.Coder.Name") lstActivities = lstActivities.OrderByDescending(o => (string)o.Distribution.Coder.Name).ToList(); else lstActivities = lstActivities.OrderByDescending(o => typeof(Activity).GetProperty(e.SortExpression).GetValue(o, null)).ToList();






Aucun commentaire:

Enregistrer un commentaire