I have this class:
public class MyClass {
public string GetText() {
return "text";
}
}
What I want is to have a generic caching method. If GetText is called, I want to intercept this call, something like;
public T MethodWasCalled<T>(MethodInfo method) {
if(Cache.Contains(method.Name)) {
return Cache[method.Name] as T;
}
else {
T result = method.Invoke();
Cache.Add(method.Name, result);
return result;
}
}
I hope the above explains what I want to accomplish. What would be a good strategy for this?