Created
October 23, 2011 18:30
-
-
Save motowilliams/1307681 to your computer and use it in GitHub Desktop.
Asp-net-MVC-Session-State-Extension-Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SessionStateExtensions | |
{ | |
public static void Put<T>(this HttpSessionStateBase httpSession, T value) where T : class | |
{ | |
httpSession[typeof (T).FullName] = value; | |
} | |
public static void Put<T>(this HttpSessionStateBase httpSession, string key, T value) where T : class | |
{ | |
httpSession[typeof (T).FullName + key] = value; | |
} | |
public static T Get<T>(this HttpSessionStateBase httpSession) where T : class | |
{ | |
var o = (T) httpSession[typeof (T).FullName]; | |
return o == null ? null : o; | |
} | |
public static T Get<T>(this HttpSessionStateBase httpSession, string key) where T : class | |
{ | |
var o = (T) httpSession[typeof (T).FullName + key]; | |
return o == null ? null : o; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment