private static object ConvertBytesToType(AdsTypeEnum adsType, byte[] value)
        {
            try
            {
                switch (adsType)
                {
                case AdsTypeEnum.Bool: return(BitConverter.ToBoolean(value, 0));

                case AdsTypeEnum.Byte: return(value[0]);

                case AdsTypeEnum.Int16: return(BitConverter.ToInt16(value, 0));

                case AdsTypeEnum.Int32: return(BitConverter.ToInt32(value, 0));

                case AdsTypeEnum.Int64: return(BitConverter.ToInt64(value, 0));

                case AdsTypeEnum.UInt16: return(BitConverter.ToUInt16(value, 0));

                case AdsTypeEnum.UInt32: return(BitConverter.ToUInt32(value, 0));

                case AdsTypeEnum.UInt64: return(BitConverter.ToUInt64(value, 0));

                case AdsTypeEnum.Single: return(BitConverter.ToSingle(value, 0));

                case AdsTypeEnum.Double: return(BitConverter.ToDouble(value, 0));

                case AdsTypeEnum.String: return(ByteArrayHelper.ByteArrayToString(value));

                case AdsTypeEnum.DateTime: return(ByteArrayHelper.ByteArrayToDateTime(value));

                case AdsTypeEnum.Date: return(new Date(BitConverter.ToUInt32(value, 0)));

                case AdsTypeEnum.Time: return(new Time(BitConverter.ToUInt32(value, 0)));

                default:
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
        private static object GetBytesFromConvertibleType(Type type, byte[] value)
        {
            object v = null;

            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Boolean: v = value[0]; break;

            case TypeCode.Byte: v = value[0]; break;

            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
                switch (value.Length)
                {
                case 2: v = BitConverter.ToInt16(value, 0); break;

                case 4: v = BitConverter.ToInt32(value, 0); break;

                case 8: v = BitConverter.ToInt64(value, 0); break;
                }
                break;

            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                switch (value.Length)
                {
                case 2: v = BitConverter.ToUInt16(value, 0); break;

                case 4: v = BitConverter.ToUInt32(value, 0); break;

                case 8: v = BitConverter.ToUInt64(value, 0); break;
                }
                break;

            case TypeCode.Single:
            case TypeCode.Double:
                switch (value.Length)
                {
                case 4: v = BitConverter.ToSingle(value, 0); break;

                case 8: v = BitConverter.ToDouble(value, 0); break;
                }
                break;

            case TypeCode.String: v = ByteArrayHelper.ByteArrayToString(value); break;

            case TypeCode.DateTime: v = ByteArrayHelper.ByteArrayToDateTime(value); break;

            case TypeCode.Object:
                if (Type.Equals(typeof(Date), type))
                {
                    v = new Date(BitConverter.ToUInt32(value, 0));
                }
                if (Type.Equals(typeof(Time), type))
                {
                    v = new Time(BitConverter.ToUInt32(value, 0));
                }
                break;

            default:
                v = null;
                break;
            }

            return(v);
        }