Esempio n. 1
0
        public void GetRuntimeType(SqlTypeCode code, Type expectedType)
        {
            var type    = PrimitiveTypes.Interval(code);
            var objType = type.GetRuntimeType();

            Assert.AreEqual(expectedType, objType);
        }
Esempio n. 2
0
        public static SqlType Deserialize(BinaryReader reader, ITypeResolver resolver)
        {
            var typeCode = (SqlTypeCode)reader.ReadByte();

            if (BooleanType.IsBooleanType(typeCode))
            {
                return(PrimitiveTypes.Boolean(typeCode));
            }
            if (IntervalType.IsIntervalType(typeCode))
            {
                return(PrimitiveTypes.Interval(typeCode));
            }
            if (DateType.IsDateType(typeCode))
            {
                return(PrimitiveTypes.DateTime(typeCode));
            }

            if (StringType.IsStringType(typeCode))
            {
                var maxSize = reader.ReadInt32();

                CultureInfo locale    = null;
                var         hasLocale = reader.ReadByte() == 1;
                if (hasLocale)
                {
                    var name = reader.ReadString();
                    locale = new CultureInfo(name);
                }

                // TODO: Get the encoding from the serialization...
                return(PrimitiveTypes.String(typeCode, maxSize, Encoding.Unicode, locale));
            }

            if (NumericType.IsNumericType(typeCode))
            {
                var size  = reader.ReadInt32();
                var scale = reader.ReadByte();

                return(PrimitiveTypes.Numeric(typeCode, size, scale));
            }

            if (BinaryType.IsBinaryType(typeCode))
            {
                var size = reader.ReadInt32();
                return(PrimitiveTypes.Binary(typeCode, size));
            }

            if (typeCode == SqlTypeCode.Type)
            {
                // TODO:
            }

            if (typeCode == SqlTypeCode.QueryPlan)
            {
                return(new QueryType());
            }

            if (typeCode == SqlTypeCode.Array)
            {
                var size = reader.ReadInt32();
                return(new ArrayType(size));
            }

            if (typeCode == SqlTypeCode.Null)
            {
                return(PrimitiveTypes.Null());
            }

            throw new NotSupportedException();
        }