Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created July 27, 2011 00:55
Show Gist options
  • Save pedroreys/1108447 to your computer and use it in GitHub Desktop.
Save pedroreys/1108447 to your computer and use it in GitHub Desktop.
right linq expression
public Expression Right(string value, int targetLenght)
{
var valueConstant = Expression.Constant(value);
var targetLenghtConstant = Expression.Constant(targetLenght);
var pi = typeof(String).GetProperty("Length");
var mi = typeof(string).GetMethod("Substring", new[] { typeof(int), typeof(int) });
var valueLenght = Expression.Property(valueConstant, pi);
var startIndex = Expression.Subtract(valueLenght, targetLenghtConstant);
var rightExpression = Expression.Call(valueConstant, mi, startIndex, targetLenght);
return rightExpression;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment