void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length)
        {
            Guid   guid        = Guid.Empty;
            string valAsString = val as string;

            byte[] valAsByte = val as byte[];

            if (val is Guid)
            {
                guid = (Guid)val;
            }
            else
            {
                try
                {
                    if (valAsString != null)
                    {
                        guid = new Guid(valAsString);
                    }
                    else if (valAsByte != null)
                    {
                        guid = new Guid(valAsByte);
                    }
                }
                catch (Exception ex)
                {
                    throw new MyCatException(Resources.DataNotInSupportedFormat, ex);
                }
            }

            if (OldGuids)
            {
                WriteOldGuid(packet, guid, binary);
            }
            else
            {
                guid.ToString("D");

                if (binary)
                {
                    packet.WriteLenString(guid.ToString("D"));
                }
                else
                {
                    packet.WriteStringNoNull("'" + MyCatHelper.EscapeString(guid.ToString("D")) + "'");
                }
            }
        }
Beispiel #2
0
        void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length)
        {
            string v = val.ToString();

            if (length > 0)
            {
                length = Math.Min(length, v.Length);
                v      = v.Substring(0, length);
            }

            if (binary)
            {
                packet.WriteLenString(v);
            }
            else
            {
                packet.WriteStringNoNull("'" + MyCatHelper.EscapeString(v) + "'");
            }
        }