Skip to content

Instantly share code, notes, and snippets.

@samandmoore
Created July 18, 2012 20:36
Show Gist options
  • Save samandmoore/3138725 to your computer and use it in GitHub Desktop.
Save samandmoore/3138725 to your computer and use it in GitHub Desktop.
public static DefaultSort GetDefaultSort<TModel, TProperty>(Expression<Func<TModel, TProperty>> expression, SortDirection direction)
{
return new DefaultSort(EvaluateExpression(expression), direction);
}
private static string EvaluateExpression(LambdaExpression expression)
{
var memberExpression = expression.Body as MemberExpression;
return memberExpression == null ? null : memberExpression.Member.Name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment