Beispiel #1
0
 public static string Encode(KristallDataType dataType, object value)
 {
     StringBuilder stringFactory = new StringBuilder();
     switch (dataType)
     {
         case (KristallDataType.String):
         {
             foreach (char character in (value as string))
             {
                 stringFactory.Append(String.Format("{0:x4}", Convert.ToInt16(character)));
             }
             return stringFactory.ToString().ToUpper();
         }
         case (KristallDataType.Boolean):
         {
             return ((bool)value ? "1" : "0");
         }
         case (KristallDataType.Integer):
         {
             return Convert.ToString((int)value, 16);
             //return int.Parse(value, System.Globalization.NumberStyles.HexNumber);
         }
     }
     throw new NotImplementedException();
 }
Beispiel #2
0
 public static object Decode(KristallDataType dataType, string value)
 {
     switch (dataType)
     {
         case (KristallDataType.String):
             {
                 StringBuilder stringFactory = new StringBuilder();
                 for (int offset = 0; offset < value.Length; offset += 4)
                 {
                     stringFactory.Append(Convert.ToChar(int.Parse(value.Substring(offset, 4),
                         System.Globalization.NumberStyles.HexNumber)));
                 }
                 return stringFactory.ToString();
             }
         case (KristallDataType.Integer):
         {
             return int.Parse(value, System.Globalization.NumberStyles.HexNumber);
         }
         case (KristallDataType.Boolean):
             {
                 return int.Parse(value) == 1 ? true : false;
             }
     }
     throw new ArgumentException();
 }