public object[] GetValues(DataReaderId readerId, int maximumNumberOfValuesToRead)
        {
            if (maximumNumberOfValuesToRead <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maximumNumberOfValuesToRead));
            }

            var reader     = _readerStore.Get(readerId);
            var values     = new object[Math.Min(reader.FieldCount, maximumNumberOfValuesToRead)];
            var lengthRead = reader.GetValues(values);

            if (lengthRead < maximumNumberOfValuesToRead)
            {
                var valuesCopy = values;
                values = new object[lengthRead];
                Array.Copy(valuesCopy, 0, values, 0, lengthRead);
            }
            for (var i = 0; i < lengthRead; i++)
            {
                if (values[i] == DBNull.Value)
                {
                    values[i] = null;                     // Replace DBNull.Value with null for the same reason as in GetValue
                }
            }
            return(values);
        }
        public Tuple <long, char[]> GetChars(DataReaderId readerId, int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
        {
            // When messages are passed over the write, the "buffer" reference on the client is serialised and then deserialised here, so
            // it's not the same array. With an IDataReader, buffer WOULD be populated - to approximate this, we have to return a new array
            // and the client has to write its contents over the original array's contents.
            var lengthRead = _readerStore.Get(readerId).GetChars(i, fieldoffset, buffer, bufferoffset, length);

            return(Tuple.Create(lengthRead, buffer));
        }
        public object GetValue(DataReaderId readerId, int i)
        {
            // If the value is null in the database then we'll get DBNull.Value here, which the WCF host won't like (it will say, if you know
            // how to trap the correct exception, something about using [KnownType] - but that can only be applied to types, not members). I'm
            // not sure how to solve this in a perfect manner, so I'm going to replace DBNull.Value with null and then do the opposite on the
            // client.
            var value = _readerStore.Get(readerId).GetValue(i);

            return((value == DBNull.Value) ? null : value);
        }
        public string[] GetFieldNames(DataReaderId readerId)
        {
            var reader     = _readerStore.Get(readerId);
            var fieldNames = new string[reader.FieldCount];

            for (var i = 0; i < fieldNames.Length; i++)
            {
                fieldNames[i] = reader.GetName(i);
            }
            return(fieldNames);
        }
        public RemoteSqlDataReaderClient(IRemoteSqlDataReader reader, DataReaderId readerId)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _reader   = reader;
            _readerId = readerId;
            _disposed = false;

            _currentColumnNamesLookupIfKnown = null;
            _valuesInCurrentRowIfKnown       = null;
        }
        public DataReaderId GetData(DataReaderId readerId, int i)
        {
            var reader = _readerStore.Get(readerId).GetData(i);

            try
            {
                return(_readerStore.Add(reader));
            }
            catch
            {
                reader.Dispose();
                throw;
            }
        }
 public string GetFieldType(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetFieldType(i).FullName);
 }
 public double GetDouble(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetDouble(i));
 }
 public int GetDepth(DataReaderId readerId)
 {
     return(_readerStore.Get(readerId).Depth);
 }
 public void Close(DataReaderId readerId)
 {
     _readerStore.Get(readerId).Close();
 }
 public DataTable GetSchemaTable(DataReaderId readerId)
 {
     return(_readerStore.Get(readerId).GetSchemaTable());
 }
 public long GetInt64(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetInt64(i));
 }
 public short GetInt16(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetInt16(i));
 }
 public char GetChar(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetChar(i));
 }
 public byte GetByte(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetByte(i));
 }
 public bool GetBoolean(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetBoolean(i));
 }
 public bool IsDBNull(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).IsDBNull(i));
 }
 public int GetRecordsAffected(DataReaderId readerId)
 {
     return(_readerStore.Get(readerId).RecordsAffected);
 }
 public bool GetIsClosed(DataReaderId readerId)
 {
     return(_readerStore.Get(readerId).IsClosed);
 }
 public float GetFloat(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetFloat(i));
 }
 public Guid GetGuid(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetGuid(i));
 }
 public void Dispose(DataReaderId readerId)
 {
     _readerStore.Get(readerId).Dispose();
     _readerStore.Remove(readerId);
 }
 public int GetInt32(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetInt32(i));
 }
 public bool NextResult(DataReaderId readerId)
 {
     return(_readerStore.Get(readerId).NextResult());
 }
 public int GetOrdinal(DataReaderId readerId, string name)
 {
     return(_readerStore.Get(readerId).GetOrdinal(name));
 }
 public DateTime GetDateTime(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetDateTime(i));
 }
 public string GetString(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetString(i));
 }
 public decimal GetDecimal(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetDecimal(i));
 }
 public string GetDataTypeName(DataReaderId readerId, int i)
 {
     return(_readerStore.Get(readerId).GetDataTypeName(i));
 }
 public int GetFieldCount(DataReaderId readerId)
 {
     return(_readerStore.Get(readerId).FieldCount);
 }