Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created February 13, 2018 05:12
Show Gist options
  • Save talkingdotnet/ad5b4596fc29e5e4458e2f5594ab6c9e to your computer and use it in GitHub Desktop.
Save talkingdotnet/ad5b4596fc29e5e4458e2f5594ab6c9e to your computer and use it in GitHub Desktop.
public static class SessionExtensions
{
public static void SetObject(this ISession session, string key, object value)
{
session.SetString(key, JsonConvert.SerializeObject(value));
}
public static T GetObject<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