Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static T GetItem<T>(string key, Func<T> defaultValue)
- {
- if (HttpContext.Current.Session[key] == null)
- {
- HttpContext.Current.Session[key] = defaultValue.Invoke();
- }
- return (T)HttpContext.Current.Session[key];
- }
- Foo foo = GetItem<Foo>("abc", () => new Foo("blah"));
- return ((T)HttpContext.Current.Session[key]) ?? defaultValue();
- public static T GetItem<T>(string key)
- where T : new()
- {
- return ((T)HttpContext.Current.Session[key]) ?? new T();
- }
- var log = SessionItem.GetItem("logger", () => NullLog.Instance)
Add Comment
Please, Sign In to add comment