Skip to content

Instantly share code, notes, and snippets.

@ChaosEngine
Created May 2, 2017 17:38
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 ChaosEngine/6e7ffa30021f1efc803a02fa5ddd1c80 to your computer and use it in GitHub Desktop.
Save ChaosEngine/6e7ffa30021f1efc803a02fa5ddd1c80 to your computer and use it in GitHub Desktop.
SessionExtensions generic type
public static class SessionExtensions
{
public static void Set<T>(this ISession session, string key, T value)
{
session.SetString(key, JsonConvert.SerializeObject(value));
}
public static T Get<T>(this ISession session, string key)
{
var value = session.GetString(key);
return value == null ?
default(T) :
JsonConvert.DeserializeObject<T>(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment