Created
July 27, 2011 00:55
-
-
Save pedroreys/1108447 to your computer and use it in GitHub Desktop.
right linq expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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