Created
May 18, 2016 19:10
-
-
Save ctigeek/5a738436d56a91cc162d47d8aaff4e43 to your computer and use it in GitHub Desktop.
Helper functions for storing data in session.
This file contains hidden or 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 void SetInt64(this ISession session, string key, long lng) | |
| { | |
| var bytes = BitConverter.GetBytes(lng); | |
| session.Set(key, bytes); | |
| } | |
| public static long GetInt64(this ISession session, string key, long defaultIfNull) | |
| { | |
| var bytes = session.Get(key); | |
| if (bytes == null || bytes.Length == 0) | |
| { | |
| return defaultIfNull; | |
| } | |
| return BitConverter.ToInt64(bytes, 0); | |
| } | |
| public static void SetDateTime(this ISession session, string key, DateTime dt) | |
| { | |
| SetInt64(session, key, dt.ToBinary()); | |
| } | |
| public static DateTime GetDateTime(this ISession session, string key, DateTime defaultIfNull) | |
| { | |
| var binTime = GetInt64(session, key, defaultIfNull.ToBinary()); | |
| return DateTime.FromBinary(binTime); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment