Example #1
0
        internal static byte[] GetBytesFromObject(Common.Enums.TagType type, object value)
        {
            byte[] result = null;

            if (value != null)
            {
                switch (type)
                {
                case Common.Enums.TagType.Numeric:
                    result = BitConverter.GetBytes(Convert.ToInt32(value));
                    break;

                case Common.Enums.TagType.Decimal:
                    result = BitConverter.GetBytes(Convert.ToDouble(value));
                    break;

                case Common.Enums.TagType.Text:
                    result = Encoding.Default.GetBytes(value.ToString());
                    break;

                case Common.Enums.TagType.Boolean:
                    result = BitConverter.GetBytes(Convert.ToBoolean(value));
                    break;

                default:
                    break;
                }
            }

            return(result);
        }
Example #2
0
        internal static object GetObjectFromBytes(Common.Enums.TagType type, byte[] value)
        {
            object result = null;

            if (value != null)
            {
                switch (type)
                {
                case Common.Enums.TagType.Numeric:
                    result = BitConverter.ToInt32(value, 0);
                    break;

                case Common.Enums.TagType.Decimal:
                    result = BitConverter.ToDouble(value, 0);
                    break;

                case Common.Enums.TagType.Text:
                    result = Encoding.Default.GetString(value);
                    break;

                case Common.Enums.TagType.Boolean:
                    result = BitConverter.ToBoolean(value, 0);
                    break;

                default:
                    break;
                }
            }
            return(result);
        }