I want to create a generic to which I can pass a function as a parameter, however this function may include parameters itself so…
int foo = GetCachedValue('LastFoo', methodToGetFoo)
Such that:
protected int methodToGetFoo(DateTime today) { return 2; // example only }
Essentially I want to have a method that will check the cache for a value, otherwise will generate the value based on the passed in method.
Thoughts?
It sounds like you want a
Func<T>:The caller can then wrap this in many ways; for simple functions:
or where arguments are involved, a closure: