Created
May 20, 2024 13:18
-
-
Save halityurttas/4804bfd497e1897d62ad075dfcb5a542 to your computer and use it in GitHub Desktop.
Property accessor
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
static Func<T, TResult> CreatePropertyAccessor<T, TResult>(string propertyName) | |
{ | |
var parameter = Expression.Parameter(typeof(T), "x"); | |
var property = Expression.Property(parameter, propertyName); | |
var lambda = Expression.Lambda<Func<T, TResult>>(property, parameter); | |
return lambda.Compile(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment