示例#1
0
 private TData AtomicExchange <TData>(string key, TData value)
 {
     if (typeof(TData) == typeof(string))
     {
         object result = redisContext.AtomicExchange(key, value as string);
         return((TData)result);
     }
     else if (typeof(TData) == typeof(int?))
     {
         object result = redisContext.AtomicExchange(key, value as int?);
         return((TData)result);
     }
     else if (typeof(TData) == typeof(int))
     {
         object result = redisContext.AtomicExchange(key, Convert.ToInt32(value));
         return((TData)result);
     }
     else if (typeof(TData) == typeof(long?))
     {
         object result = redisContext.AtomicExchange(key, value as long?);
         return((TData)result);
     }
     else if (typeof(TData) == typeof(long))
     {
         object result = redisContext.AtomicExchange(key, Convert.ToInt64(value));
         return((TData)result);
     }
     else if (typeof(TData) == typeof(double?))
     {
         object result = redisContext.AtomicExchange(key, value as double?);
         return((TData)result);
     }
     else if (typeof(TData) == typeof(double))
     {
         object result = redisContext.AtomicExchange(key, Convert.ToDouble(value));
         return((TData)result);
     }
     else if (typeof(TData) == typeof(bool?))
     {
         object result = redisContext.AtomicExchange(key, value as bool?);
         return((TData)result);
     }
     else if (typeof(TData) == typeof(bool))
     {
         object result = redisContext.AtomicExchange(key, Convert.ToBoolean(value));
         return((TData)result);
     }
     else
     {
         throw new NotSupportedException($"{nameof(TData)} is not supported");
     }
 }