Skip to content

Instantly share code, notes, and snippets.

@halityurttas
Created May 20, 2024 13:18
Show Gist options
  • Save halityurttas/4804bfd497e1897d62ad075dfcb5a542 to your computer and use it in GitHub Desktop.
Save halityurttas/4804bfd497e1897d62ad075dfcb5a542 to your computer and use it in GitHub Desktop.
Property accessor
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