Extract information from a Func<bool, T> or alike lambda
- by Syska
I''m trying to build a generic cache layer. ICacheRepository
Say I have the following:
public class Person
{
public int PersonId { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public DateTime Added { get; set; }
}
And I have something like this:
list.Where(x => x.Firstname == "Syska");
Here I want to extract the above information, to see if the query supplied the "PersonId" which it did not, so I dont want to cache it.
But lets say I run a query like this:
list.Where(x => x.PersonId == 10);
Since PersonId is my key ... I want to cache it. with the key like "Person_10" and I later can fetch it from the cache.
I know its possible to extract the information with Expression<Func<>> but there seems to be a big overhead of doing this (when running compile and extract the Constant values etc. and a bunch of cache to be sure to parse right)
Are there a framework for this? Or some smart/golden way of doing this ?