What does P mean in Sort(Expression<Func<T, P>> expr, ListSortDirection direction)?

Posted by Grasshopper on Stack Overflow See other posts from Stack Overflow or by Grasshopper
Published on 2012-08-31T15:34:50Z Indexed on 2012/08/31 15:38 UTC
Read the original article Hit count: 163

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);
    }
}

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about sorting