/// <summary> /// Reads the value of a cell from the file wrapper, checks to see if it null using /// <paramref name="isNullFunc"/>, and converts it to the proper output type using /// <paramref name="convertFunc"/>. /// </summary> /// <param name="offset">Offset into the file to read from</param> /// <param name="rowId">Internal ID of the row to set on all cells in this row</param> /// <param name="convertFunc">Function to use to convert the buffer to the target type</param> /// <param name="isNullFunc"> /// If provided, this function will be used to determine if the value is null /// </param> /// <param name="toStringFunc">Optional function to use to convert the object to a string.</param> /// <typeparam name="T">The expected type of the cell. Used to keep the code honest</typeparam> /// <returns>The object, a display value, and the length of the value + its length</returns> private FileStreamReadResult ReadCellHelper <T>(long offset, long rowId, Func <int, T> convertFunc, Func <int, bool> isNullFunc = null, Func <T, string> toStringFunc = null) { LengthResult length = ReadLength(offset); DbCellValue result = new DbCellValue { RowId = rowId }; if (isNullFunc == null ? length.ValueLength == 0 : isNullFunc(length.TotalLength)) { result.RawObject = null; result.DisplayValue = SR.QueryServiceCellNull; result.IsNull = true; } else { AssureBufferLength(length.ValueLength); fileStream.Read(buffer, 0, length.ValueLength); T resultObject = convertFunc(length.ValueLength); result.RawObject = resultObject; result.DisplayValue = toStringFunc == null?result.RawObject.ToString() : toStringFunc(resultObject); result.IsNull = false; } return(new FileStreamReadResult(result, length.TotalLength)); }
/// <summary> /// Reads the value of a cell from the file wrapper, checks to see if it null using /// <paramref name="isNullFunc"/>, and converts it to the proper output type using /// <paramref name="convertFunc"/>. /// </summary> /// <param name="offset">Offset into the file to read from</param> /// <param name="rowId">Internal ID of the row to set on all cells in this row</param> /// <param name="convertFunc">Function to use to convert the buffer to the target type</param> /// <param name="isNullFunc"> /// If provided, this function will be used to determine if the value is null /// </param> /// <param name="toStringFunc">Optional function to use to convert the object to a string.</param> /// <param name="setInvariantCultureDisplayValue">Optional parameter indicates whether the culture invariant display value should be provided.</param> /// <typeparam name="T">The expected type of the cell. Used to keep the code honest</typeparam> /// <returns>The object, a display value, and the length of the value + its length</returns> private FileStreamReadResult ReadCellHelper <T>(long offset, long rowId, Func <int, T> convertFunc, Func <int, bool> isNullFunc = null, Func <T, string> toStringFunc = null, bool setInvariantCultureDisplayValue = false) { LengthResult length = ReadLength(offset); DbCellValue result = new DbCellValue { RowId = rowId }; if (isNullFunc == null ? length.ValueLength == 0 : isNullFunc(length.TotalLength)) { result.RawObject = null; result.DisplayValue = SR.QueryServiceCellNull; result.IsNull = true; } else { AssureBufferLength(length.ValueLength); fileStream.Read(buffer, 0, length.ValueLength); T resultObject = convertFunc(length.ValueLength); result.RawObject = resultObject; result.DisplayValue = toStringFunc == null?result.RawObject.ToString() : toStringFunc(resultObject); if (setInvariantCultureDisplayValue) { string icDisplayValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", result.RawObject); // Only set the value when it is different from the DisplayValue to reduce the size of the result // if (icDisplayValue != result.DisplayValue) { result.InvariantCultureDisplayValue = icDisplayValue; } } result.IsNull = false; } return(new FileStreamReadResult(result, length.TotalLength)); }