Created
November 13, 2018 10:21
-
-
Save Criteo-dotnet-blog/2bd11a8181a8ed9ed5b04b15930a73be to your computer and use it in GitHub Desktop.
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
private static Func<Process, string> GetProcessNameAccessor() | |
{ | |
var param = Expression.Parameter(typeof(Process), "arg"); | |
var processInfoMember = Expression.Field(param, "processInfo"); | |
var processNameMember = Expression.Field(processInfoMember, "processName"); | |
var lambda = Expression.Lambda(typeof(Func<Process, string>), processNameMember, param); | |
return (Func<Process, string>)lambda.Compile(); | |
} | |
private static readonly Func<Process, string> _getProcessNameFunc = GetProcessNameAccessor (); | |
public string GetProcessNameByExpression() | |
{ | |
return _getProcessNameFunc(_process); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment