Example #1
0
 static void SetValue(T value, out byte[] val)
 {
     byte[] temp = new byte[] { };
     if (typeof(T) == typeof(long))
     {
         var lVal = Convert.ChangeType(value, typeof(long));
         if (lVal != null)
         {
             temp = BitConverter.GetBytes((long)lVal);
         }
     }
     else if (typeof(T) == typeof(float))
     {
         var lVal = Convert.ChangeType(value, typeof(float));
         if (lVal != null)
         {
             temp = BitConverter.GetBytes((float)lVal);
         }
     }
     else if (typeof(T) == typeof(double))
     {
         var lVal = Convert.ChangeType(value, typeof(double));
         if (lVal != null)
         {
             temp = BitConverter.GetBytes((double)lVal);
         }
     }
     val = ENumEncryptUtils.EncryptDes(temp);
 }
Example #2
0
        static T GetVal(byte[] value)
        {
            byte[] temp   = ENumEncryptUtils.DecryptDes(value);
            var    result = new object();

            if (typeof(T) == typeof(long))
            {
                result = BitConverter.ToInt64(temp, 0);
            }
            if (typeof(T) == typeof(float))
            {
                result = BitConverter.ToSingle(temp, 0);
            }
            if (typeof(T) == typeof(double))
            {
                result = BitConverter.ToDouble(temp, 0);
            }
            var valTemp = Convert.ChangeType(result, typeof(T));

            if (valTemp != null)
            {
                return((T)valTemp);
            }
            throw new Exception("Impossible!");
        }