public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (!(value is Guid))
            {
                return(null);
            }

            Guid guid = ((Guid)value);

            if (destinationType == typeof(DateTime))
            {
                return(GuidGenerator.GetDateTime(guid));
            }

            if (destinationType == typeof(DateTimeOffset))
            {
                return(GuidGenerator.GetDateTimeOffset(guid));
            }

            if (destinationType == typeof(byte[]))
            {
                return(CassandraConversionHelper.ConvertGuidToBytes((Guid)value));
            }

            if (destinationType == typeof(Guid))
            {
                return(guid);
            }

            return(null);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value is Guid)
            {
                return(CassandraConversionHelper.ConvertGuidToBytes((Guid)value));
            }

            byte[] bytes = null;

            if (value is byte[])
            {
                bytes = (byte[])value;
            }
            else if (value is DateTimeOffset)
            {
                bytes = BitConverter.GetBytes(((DateTimeOffset)value).UtcTicks);
            }

            if (bytes == null)
            {
                switch (Type.GetTypeCode(value.GetType()))
                {
                case TypeCode.Byte:
                    bytes = new byte[] { (byte)value }; break;

                case TypeCode.SByte:
                    bytes = new byte[] { Convert.ToByte((sbyte)value) }; break;

                case TypeCode.DateTime:
                    bytes = BitConverter.GetBytes(((DateTime)value).Ticks); break;

                case TypeCode.Boolean:
                    bytes = BitConverter.GetBytes((bool)value); break;

                case TypeCode.Char:
                    bytes = BitConverter.GetBytes((char)value); break;

                case TypeCode.Double:
                    bytes = BitConverter.GetBytes((double)value); break;

                case TypeCode.Int16:
                    bytes = BitConverter.GetBytes((short)value); break;

                case TypeCode.Int32:
                    bytes = BitConverter.GetBytes((int)value); break;

                case TypeCode.Int64:
                    bytes = BitConverter.GetBytes((long)value); break;

                case TypeCode.Single:
                    bytes = BitConverter.GetBytes((float)value); break;

                case TypeCode.UInt16:
                    bytes = BitConverter.GetBytes((ushort)value); break;

                case TypeCode.UInt32:
                    bytes = BitConverter.GetBytes((uint)value); break;

                case TypeCode.UInt64:
                    bytes = BitConverter.GetBytes((ulong)value); break;

                case TypeCode.Decimal:
                    bytes = FromDecimal((decimal)value); break;

                case TypeCode.String:
                    bytes = Encoding.UTF8.GetBytes((string)value); break;

                default:
                    break;
                }
            }

            if (bytes == null)
            {
                return(null);
            }

            return(CassandraConversionHelper.ConvertEndian(bytes));
        }