public void PrepareWrite(object value, NpgsqlBuffer buf, LengthCache lengthCache, NpgsqlParameter parameter = null) { _buf = buf; _charPos = -1; _byteLen = lengthCache.GetLast(); if (parameter != null && parameter.ConvertedValue != null) { value = parameter.ConvertedValue; } switch (Type.GetTypeCode(value.GetType())) { case TypeCode.String: _str = (string)value; _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _str.Length ? _str.Length : parameter.Size; return; case TypeCode.Object: Contract.Assert(value is char[]); _chars = (char[])value; _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _chars.Length ? _chars.Length : parameter.Size; return; case TypeCode.Char: _singleCharArray[0] = (char)value; _chars = _singleCharArray; _charLen = 1; return; default: value = Convert.ToString(value); goto case TypeCode.String; } }
public void PrepareWrite(object value, NpgsqlBuffer buf, LengthCache lengthCache, NpgsqlParameter parameter = null) { _buf = buf; _charPos = -1; _byteLen = lengthCache.GetLast(); _str = value as string; if (_str != null) { _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _str.Length ? _str.Length : parameter.Size; return; } _chars = value as char[]; if (_chars != null) { _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _chars.Length ? _chars.Length : parameter.Size; return; } if (value is char) { _singleCharArray[0] = (char)value; _chars = _singleCharArray; _charLen = 1; return; } throw PGUtil.ThrowIfReached(); }
public override void PrepareWrite(object value, WriteBuffer buf, LengthCache lengthCache, NpgsqlParameter parameter = null) { _writeBuf = buf; _charPos = -1; _byteLen = lengthCache.GetLast(); if (parameter?.ConvertedValue != null) { value = parameter.ConvertedValue; } _str = value as string; if (_str != null) { _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _str.Length ? _str.Length : parameter.Size; return; } _chars = value as char[]; if (_chars != null) { _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _chars.Length ? _chars.Length : parameter.Size; return; } if (value is char) { _singleCharArray[0] = (char)value; _chars = _singleCharArray; _charLen = 1; return; } _str = Convert.ToString(value); _charLen = parameter == null || parameter.Size <= 0 || parameter.Size >= _str.Length ? _str.Length : parameter.Size; }