Extract information from a Func<bool, T> or alike lambda

Posted by Syska on Stack Overflow See other posts from Stack Overflow or by Syska
Published on 2011-02-03T23:09:02Z Indexed on 2011/02/03 23:25 UTC
Read the original article Hit count: 161

Filed under:
|
|

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 ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET