Created
May 17, 2020 23:54
-
-
Save zHaytam/7894be5035e2b96c2d1c80da8c4a1a74 to your computer and use it in GitHub Desktop.
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
public static Expression<Func<TEntity, object>> GetPropertyGetter<TEntity>(string property) | |
{ | |
if (property == null) | |
throw new ArgumentNullException(nameof(property)); | |
var param = Expression.Parameter(typeof(TEntity)); | |
var prop = param.GetNestedProperty(property); | |
var convertedProp = Expression.Convert(prop, typeof(object)); | |
return Expression.Lambda<Func<TEntity, object>>(convertedProp, param); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment