What does P mean in Sort(Expression<Func<T, P>> expr, ListSortDirection direction)?
- by Grasshopper
I am attempting to use the answer in post: How do you sort an EntitySet<T> to expose an interface so that I can sort an EntitySet with a Binding list. I have created the class below and I get the following compiler error: "The type or namespace 'P' could not be found (are you missing a using directive or assembly reference?). Can someone tell me what the P means and which namespace I need to include to get the method below to compile? I am very new to delegates and lamba expressions.
Also, can someone confirm that if I create a BindingList from my EntitySet that any modifications I make to the BindingList will be made to the EntitySet?
Basically, I have an EntitySet that I need to sort and make changes to. Then, I will need to persist these changes using the original Entity that the BindingList came from.
public class EntitySetBindingWrapper<T> : BindingList<T>
{
public EntitySetBindingWrapper(BindingList<T> root)
: base(root)
{
}
public void Sort(Expression<Func<T, P>> expr, ListSortDirection direction)
{
if (expr == null)
base.RemoveSortCore();
MemberExpression propExpr = expr as MemberExpression;
if (propExpr == null) throw new ArgumentException("You must provide a property", "expr");
PropertyDescriptorCollection descriptorCol = TypeDescriptor.GetProperties(typeof(T));
IEnumerable<PropertyDescriptor> descriptors = descriptorCol.Cast<PropertyDescriptor>();
PropertyDescriptor descriptor = descriptors.First(pd => pd.Name == propExpr.Member.Name);
base.ApplySortCore(descriptor, direction);
}
}