It has been hard at least for me.
This method applies the value to the specified property of the target items:
private static void SetPropertyToAll<T, TValue>(IEnumerable<T> targetItems, Expression<Func<T, TValue>> propertyExpression, TValue value) { if (propertyExpression.Body is MemberExpression) { var memberExpression = (MemberExpression)propertyExpression.Body; var propInfo = (PropertyInfo)memberExpression.Member; foreach (var item in targetItems) { propInfo.SetValue(item, value, null); } } else { throw new InvalidOperationException("See link to the Stack Overflow question below!!"); } }
And this is the original question in which I found all the information I needed in order for this to work like fine cinnamon 😉
http://stackoverflow.com/a/2789606/1025407
Good luck, Expression Boy!