Esempio n. 1
0
 /// <summary>
 /// Helper method to call <see cref="AsyncDataColumn.TryGetValueAsync"/> if <paramref name="rawBytes"/> is <c>null</c>, or keep reading raw bytes into <paramref name="rawBytes"/>  using <see cref="AsyncDataColumn.ReadBytesAsync(Byte[], Int32, Int32)"/> until all required bytes have been read.
 /// </summary>
 /// <param name="stream">This <see cref="AsyncDataColumn"/>.</param>
 /// <param name="rawBytes">The byte array to read to using <see cref="AsyncDataColumn.ReadBytesAsync(Byte[], Int32, Int32)"/>, or <c>null</c> to use <see cref="AsyncDataColumn.TryGetValueAsync"/> instead.</param>
 /// <returns>A task which will always return <c>true</c> on completion.</returns>
 public static async ValueTask <Boolean> SkipBytesAsync(this AsyncDataColumn stream, Byte[] rawBytes)
 {
     if (rawBytes == null)
     {
         await stream.TryGetValueAsync();
     }
     else
     {
         while (((await stream.ReadBytesAsync(rawBytes, 0, rawBytes.Length)) ?? 0) != 0)
         {
             ;
         }
     }
     return(false);
 }
Esempio n. 2
0
    /// <summary>
    /// Helper method to asynchronously try to get value and cast it to given type, or throw an exception if value can not be fetched or cast is invalid.
    /// </summary>
    /// <param name="column">This <see cref="AsyncDataColumn"/>.</param>
    /// <param name="type">The type to cast value to.</param>
    /// <returns>A task which will on completion contain casted value.</returns>
    /// <exception cref="NullReferenceException">If this <see cref="AsyncDataColumn"/> is <c>null</c>.</exception>
    /// <exception cref="InvalidOperationException">If fetching value fails (<see cref="AsyncDataColumn.TryGetValueAsync"/> method returns such <see cref="ResultOrNone{TResult}"/> that its <see cref="ResultOrNone{TResult}.HasResult"/> property is <c>false</c>).</exception>
    public static async ValueTask <Object> GetValueAsync(this AsyncDataColumn column, Type type)
    {
        var retValOrNone = await column.TryGetValueAsync();

        Object retVal;

        if (retValOrNone.HasResult)
        {
            retVal = retValOrNone.Result;
            if (retVal != null && !type.GetTypeInfo().IsAssignableFrom(retVal.GetType().GetTypeInfo()))
            {
                retVal = column.MetaData.ChangeType(retVal, type);
            }
        }
        else
        {
            throw new InvalidOperationException($"No value for index {column.ColumnIndex}.");
        }

        return(retVal);
    }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="DataColumnSUKS"/> with given parameters.
        /// </summary>
        /// <param name="metadata">The column <see cref="DataColumnMetaData"/>.</param>
        /// <param name="columnIndex">The index of this column in <see cref="AsyncDataRow"/> it was obtained from.</param>
        /// <param name="previousColumn">The previous <see cref="DataColumnSUKS"/> column of the <see cref="AsyncDataRow"/> this belongs to.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="metadata"/> is <c>null</c>, or if <paramref name="columnIndex"/> is greater than <c>0</c> but <paramref name="previousColumn"/> is <c>null</c>.</exception>
        public DataColumnSUKS(
            DataColumnMetaData metadata,
            Int32 columnIndex,
            AsyncDataColumn previousColumn
            ) : base(metadata, columnIndex)
        {
            if (columnIndex > 0)
            {
                ArgumentValidator.ValidateNotNull(nameof(previousColumn), previousColumn);
            }

            this._totalBytesRead = 0;
            this._byteCount      = new ReadOnlyResettableAsyncLazy <Int32>(async() =>
            {
                if (previousColumn != null)
                {
                    await previousColumn.SkipBytesAsync(null);
                }
                return(await this.ReadByteCountAsync());
            });
        }
Esempio n. 4
0
 /// <summary>
 /// Helper method to asynchronously try to get value as is and return it as <see cref="Object"/>, or throw an exception if value can not be fetched or cast is invalid.
 /// </summary>
 /// <param name="column">This <see cref="AsyncDataColumn"/>.</param>
 /// <returns>A task which will on completion contain casted value.</returns>
 /// <exception cref="NullReferenceException">If this <see cref="AsyncDataColumn"/> is <c>null</c>.</exception>
 /// <exception cref="InvalidOperationException">If fetching value fails (<see cref="AsyncDataColumn.TryGetValueAsync"/> method returns such <see cref="ResultOrNone{TResult}"/> that its <see cref="ResultOrNone{TResult}.HasResult"/> property is <c>false</c>).</exception>
 public static ValueTask <Object> GetValueAsObjectAsync(this AsyncDataColumn column)
 {
     return(column.GetValueAsync(typeof(Object)));
 }
Esempio n. 5
0
 /// <summary>
 /// Helper method to asynchronously try to get value and cast it to given type, which is known at compile time, or throw an exception if value can not be fetched or cast is invalid.
 /// </summary>
 /// <typeparam name="T">The type to cast value to.</typeparam>
 /// <param name="column">This <see cref="AsyncDataColumn"/>.</param>
 /// <returns>A task which will on completion contain casted value.</returns>
 /// <exception cref="NullReferenceException">If this <see cref="AsyncDataColumn"/> is <c>null</c>.</exception>
 /// <exception cref="InvalidOperationException">If fetching value fails (<see cref="AsyncDataColumn.TryGetValueAsync"/> method returns such <see cref="ResultOrNone{TResult}"/> that its <see cref="ResultOrNone{TResult}.HasResult"/> property is <c>false</c>).</exception>
 public static async ValueTask <T> GetValueAsync <T>(this AsyncDataColumn column)
 {
     return((T)(await column.GetValueAsync(typeof(T))));
 }
Esempio n. 6
0
 public TestDataColumn(DataColumnMetaData md, Int32 columnIndex, AsyncDataColumn prevColumn, Int32 value)
     : base(md, columnIndex, prevColumn)
 {
     this._array = new Byte[sizeof(Int32)];
     this._array.WriteInt32LEToBytesNoRef(0, value);
 }