jeudi 20 juillet 2017

Return empty if property doesn't exist in class

I have one predicate that is searching from a collection,i want to check if my class property is not in the object then i want to return empty i.e "" not null.

 Func<IModel, string> predicateField03 = s => s.GetType().GetProperty("Field03") != null && s.Field03.ToLower().Contains(filter.ToLower()) ? s.Field03.ToLower() : string.Empty;

Above query returns in object as Field03=null but i want result like Field03="" Where i am doing wrong please correct.





Aucun commentaire:

Enregistrer un commentaire