Exemple #1
0
 internal static void Set <T>(ISession session, string key, object value)
 {
     if (typeof(T) == typeof(int))
     {
         int?test = Nullable.Int32(value);
         if (!test.HasValue)
         {
             throw new ArgumentException("value must be a valid int.");
         }
         session.SetInt32(key, test.Value);
     }
     else
     {
         if (typeof(T) == typeof(Guid))
         {
             Guid?test = Nullable.Guid(value);
             if (!test.HasValue)
             {
                 throw new ArgumentException("value must be a valid guid.");
             }
         }
         else if (typeof(T) != typeof(string))
         {
             throw new ArgumentException("value is an unsupported type.");
         }
         else if (string.IsNullOrEmpty(value.ToString()))
         {
             throw new ArgumentException("value string cannot be empty");
         }
         session.SetString(key, value.ToString());
     }
 }
Exemple #2
0
        /// <summary>
        /// Manual conversion of GUID necessary due to ChangeType throwing an exception when converting valid GUIDs.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        internal static Guid?Get(ISession session, string key)
        {
            var sessionObject = Get <object>(session, key);

            return(Nullable.Guid(sessionObject));
        }