Let’s say you have a Generic Class which have a List<T> Items;
Now think of this basic lambda expression:
var result = Items.FindAll(x => x.Name = "Filip");
This will only work as long as we Know the Properties of T, which you don’t when it’s a generic type.
Therefore I would like to fetch the properties using Reflection like this:
PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public);
and somehow combind that with the above Lambda-expression so that it searches All the public properties of the Type and see if it contains “Filip”, at this time I do not care if the property-name is Name or not.
Is this possible?
Obviously this is a simplistic, optimistic string comparison (you might want to use
string.Compare, for example), but this should make the idea clear.Edit
dtb makes a good suggestion in using expression trees. You could accomplish what you’re after in a faster fashion like this:
This will allow you to do something like this: