Skip to content

Instantly share code, notes, and snippets.

@MarcosMeli
Last active August 10, 2016 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcosMeli/3065df37fc8f3472ec1585cdfe824146 to your computer and use it in GitHub Desktop.
Save MarcosMeli/3065df37fc8f3472ec1585cdfe824146 to your computer and use it in GitHub Desktop.
public static T ItemGetOrSet<T>(this HttpRequestBase request, string key, Func<T> calculator) where T: class
{
if (request.RequestContext.HttpContext.Items.Contains(key))
return (T) request.RequestContext.HttpContext.Items[key];
var val = calculator();
request.RequestContext.HttpContext.Items[key] = val;
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment