public static ViewInfo FromBinary(ISqlBinary binary) { using (var stream = binary.GetInput()) { var serializer = new BinarySerializer(); return((ViewInfo)serializer.Deserialize(stream)); } }
public static SqlXmlNode XmlType(ISqlBinary binary) { var len = binary.Length; var content = new byte[len]; var offset = 0; const int bufferSize = 1024 * 10; using (var stream = binary.GetInput()) { using (var reader = new BinaryReader(stream)) { while (true) { var buffer = new byte[bufferSize]; var readCount = reader.Read(buffer, 0, bufferSize); Array.Copy(buffer, 0, content, offset, readCount); if (readCount == 0) { break; } offset += readCount; } } } return(new SqlXmlNode(content)); }
private SqlDateTime ToDate(ISqlBinary binary) { if (binary == null) { throw new InvalidCastException(); } var bytes = binary.ToArray(); return(new SqlDateTime(bytes)); }
private ISqlValue ToString(ISqlBinary binary, SqlCharacterType destType) { if (binary == null) { throw new InvalidCastException(); } var bytes = binary.ToArray(); var s = new SqlString(bytes); return(destType.NormalizeValue(s)); }
private SqlBoolean ToBoolean(ISqlBinary binary) { if (binary.Length != 1) { throw new InvalidCastException("Exactly one byte needed to cast to boolean."); } var b = binary.First(); if (b != 0 && b != 1) { throw new InvalidCastException("The first byte of the binary is invalid for a boolean"); } return(b == 1); }
private SqlBoolean ToBoolean(ISqlBinary binary) { if (binary.Length != 1) { throw new InvalidCastException(); } var b = binary.First(); if (b != 0 && b != 1) { throw new InvalidCastException(); } return(b == 1); }
private ISqlValue ToNumber(ISqlBinary value, SqlNumericType destType) { if (value == null) { throw new InvalidCastException(); } var precision = destType.Precision; var scale = destType.Scale; if (precision <= 0) { throw new NotSupportedException(); } if (scale <= 0) { scale = 1; } // TODO: handle the cases when precision and/or scale are not set return(new SqlNumber(value.ToArray(), scale, precision)); }
private SqlBoolean ToBoolean(ISqlBinary binary) { if (binary.Length != 1) throw new InvalidCastException(); var b = binary.First(); if (b != 0 && b != 1) throw new InvalidCastException(); return b == 1; }
public static SqlXmlNode XmlType(ISqlBinary binary) { var len = binary.Length; var content = new byte[len]; var offset = 0; const int bufferSize = 1024 * 10; using (var stream = binary.GetInput()) { using (var reader = new BinaryReader(stream)) { while (true) { var buffer = new byte[bufferSize]; var readCount = reader.Read(buffer, 0, bufferSize); Array.Copy(buffer, 0, content, offset, readCount); if (readCount == 0) break; offset += readCount; } } } return new SqlXmlNode(content); }
public static ViewInfo FromBinary(ISqlBinary binary) { using (var stream = binary.GetInput()) { var serializer = new BinarySerializer(); return (ViewInfo) serializer.Deserialize(stream); } }