-
-
Save AbraaoAlves/3297963 to your computer and use it in GitHub Desktop.
Get expression equal from string
This file contains hidden or 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
Func<T, bool> GetExpressionOfEquals<T>(string propertyName, string equalsTo) | |
{ | |
var parameter = Expression.Parameter(typeof(T)); | |
var property = Expression.Property(parameter, propertyName); | |
var binaryExpression = Expression.Equal(property, Expression.Constant(equalsTo)); | |
var lambda = Expression.Lambda<Func<T, bool>>(binaryExpression, "Teste", new[] { parameter }); | |
var expression = lambda.Compile(); | |
return expression; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment