/// <summary> /// Gets a value of the specified column of the current row. /// </summary> /// <param name="column">The column.</param> /// <returns>A column value.</returns> /// <exception cref="ArgumentNullException"><paramref name="column"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// The column is from different table instance. /// </exception> /// <exception cref="InvalidOperationException"> /// No row is loaded. The <see cref="Read"/> method returned <c>false</c> or it has not been called yet.<br /> /// -- or --<br /> /// The underlying stream is non-seekable and columns are read out of order. /// </exception> /// <exception cref="ObjectDisposedException">The parent table is disposed.</exception> public virtual object GetValue(IColumn column) { CheckColumn(column); var columnBase = (Column)column; byte[] fieldCache = null; MemoCache memoItem = null; if (columnBase.dbfType == NativeColumnType.Memo) { // for detached mode and performance: return cached memo value if available or read it and store to cache Debug.Assert(memoCache != null); memoItem = Array.Find(memoCache, (c => c.column == column)); Debug.Assert(memoItem != null); fieldCache = memoItem.data; } object ret = columnBase.LoadValueAsObject(_buffer, ref fieldCache); if (memoItem != null) { memoItem.data = fieldCache; } return(ret); }
/// <summary> /// Gets a value of the specified column of the current row. /// </summary> /// <typeparam name="T">The column type.</typeparam> /// <param name="column">The column.</param> /// <returns>A column value.</returns> /// <exception cref="ArgumentNullException"><paramref name="column"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// The column is from different table instance. /// </exception> /// <exception cref="InvalidOperationException"> /// No row is loaded. The <see cref="Read"/> method returned <c>false</c> or it has not been called yet.<br /> /// -- or --<br /> /// The underlying stream is non-seekable and columns are read out of order. /// </exception> /// <exception cref="ObjectDisposedException">The parent table is disposed.</exception> public T GetValue <T>(IColumn column) { CheckColumn(column); if (!typeof(T).IsAssignableFrom(column.type)) { throw new ArgumentOutOfRangeException("column", "The column's type does not match the method's return type."); } //if (column.type != typeof(T)) //{ // throw new ArgumentOutOfRangeException("column", "The column's type does not match the method's return type."); //} var typedColumn = (Column <T>)column; byte[] fieldCache = null; MemoCache memoItem = null; if (typedColumn.dbfType == NativeColumnType.Memo) { // for detached mode and performance: return cached memo value if available or read it and store to cache Debug.Assert(memoCache != null); memoItem = Array.Find(memoCache, (c => c.column == typedColumn)); Debug.Assert(memoItem != null); fieldCache = memoItem.data; } T ret = typedColumn.LoadValue(_buffer, ref fieldCache); if (memoItem != null) { memoItem.data = fieldCache; } return(ret); }
internal const int forInsert_recNoValue = int.MinValue; // value of recNo if this row wait for insert to a DbfTable /// <summary> /// Contructor of row. /// </summary> /// <param name="recNo">No. of row in dbf file (first is 0)</param> /// <param name="buffer">bytes of entire record content</param> /// <param name="columns">DbfTable header information for detached mode</param> protected internal DbfRow(int recNo, byte[] buffer, IColumn[] columns, Guid dbfTableClassID) { this._columns = columns; this._buffer = buffer; this._recNo = recNo; this._dbfTableClassID = dbfTableClassID; // var memoColumns = Array.FindAll(_columns, (c => c.dbfType == NativeColumnType.Memo)); if (memoColumns.Length > 0) { memoCache = new MemoCache[memoColumns.Length]; for (int i = 0; i < memoColumns.Length; i++) { memoCache[i] = new MemoCache(); memoCache[i].column = memoColumns[i]; // Identifier of memo field } } }