2013-03-31 00:56:34 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
namespace Marr.Data.QGen
|
|
|
|
{
|
|
|
|
public class SortColumn<T>
|
|
|
|
{
|
|
|
|
public SortColumn(Expression<Func<T, object>> sortExpression, SortDirection direction)
|
2013-05-07 05:32:43 +03:00
|
|
|
{
|
|
|
|
MemberExpression me = GetMemberExpression(sortExpression.Body);
|
|
|
|
DeclaringType = me.Expression.Type;
|
|
|
|
PropertyName = me.Member.Name;
|
|
|
|
Direction = direction;
|
|
|
|
}
|
|
|
|
|
2013-05-07 10:22:19 +03:00
|
|
|
public SortColumn(Type declaringType, string propertyName, SortDirection direction)
|
2013-03-31 00:56:34 +03:00
|
|
|
{
|
|
|
|
DeclaringType = declaringType;
|
|
|
|
PropertyName = propertyName;
|
|
|
|
Direction = direction;
|
|
|
|
}
|
|
|
|
|
2013-05-07 10:22:19 +03:00
|
|
|
public SortDirection Direction { get; private set; }
|
2013-03-31 00:56:34 +03:00
|
|
|
public Type DeclaringType { get; private set; }
|
|
|
|
public string PropertyName { get; private set; }
|
|
|
|
|
|
|
|
private MemberExpression GetMemberExpression(Expression exp)
|
|
|
|
{
|
|
|
|
MemberExpression me = exp as MemberExpression;
|
|
|
|
|
|
|
|
if (me == null)
|
|
|
|
{
|
|
|
|
var ue = exp as UnaryExpression;
|
|
|
|
me = ue.Operand as MemberExpression;
|
|
|
|
}
|
|
|
|
|
|
|
|
return me;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum SortDirection
|
|
|
|
{
|
|
|
|
Asc,
|
|
|
|
Desc
|
|
|
|
}
|
|
|
|
}
|