예제 #1
0
        public static void SerializeTo(Stream stream, SqlType type)
        {
            var writer = new BinaryWriter(stream, Encoding.Unicode);

            SerializeTo(writer, type);
        }
예제 #2
0
        public static void SerializeTo(BinaryWriter writer, SqlType type)
        {
            writer.Write((byte)type.TypeCode);

            if (type.IsPrimitive)
            {
                if (type is NumericType)
                {
                    var numericType = (NumericType)type;
                    writer.Write(numericType.Size);
                    writer.Write(numericType.Scale);
                }
                else if (type is StringType)
                {
                    var stringType = (StringType)type;
                    writer.Write(stringType.MaxSize);

                    if (stringType.Locale != null)
                    {
                        writer.Write((byte)1);
                        writer.Write(stringType.Locale.Name);
                    }
                    else
                    {
                        writer.Write((byte)0);
                    }
                }
                else if (type is BinaryType)
                {
                    var binaryType = (BinaryType)type;

                    writer.Write(binaryType.MaxSize);
                }
                else if (type is BooleanType ||
                         type is IntervalType ||
                         type is DateType ||
                         type is NullType)
                {
                    // nothing to add to the SQL Type Code
                }
                else
                {
                    throw new NotSupportedException(String.Format("The data type '{0}' cannot be serialized.", type.GetType().FullName));
                }
            }
            else if (type is UserType)
            {
                var userType = (UserType)type;
                writer.Write((byte)1);                  // The code of custom type
                writer.Write(userType.FullName.FullName);
            }
            else if (type is QueryType)
            {
                // nothing to do for the Query Type here
            }
            else if (type is ArrayType)
            {
                var arrayType = (ArrayType)type;
                writer.Write(arrayType.Length);
            }
            else
            {
                throw new NotSupportedException();
            }
        }