Beispiel #1
0
        internal static T[] ToArrayAsync(SqlDataReader Reader, CancellationToken CancellationToken)
        {
            int size  = 64;
            int index = 0;

            T[] items = new T[size];

            CommandToken <T> token = new CommandToken <T>(Reader.GetSchemaTable());

            if (!CallBackDataSetters.TryGetValue(token, out Func <SqlDataReader, T> SetCallBackData))
            {
                CallBackDataSetters.Add(token, SetCallBackData = token.GenerateCallBackDataSetter());
            }

            while (Reader.ReadAsync(CancellationToken).Result)
            {
                T item = SetCallBackData(Reader);

                items[index++] = item;

                if (index == size)
                {
                    size *= 2;
                    T[] new_items = new T[size];
                    Array.Copy(items, 0, new_items, 0, items.Length);
                    items = new_items;
                }
            }

            T[] result_items = new T[index];
            Array.Copy(items, 0, result_items, 0, index);
            items = result_items;

            return(items);
        }
Beispiel #2
0
        internal static T First(SqlDataReader Reader)
        {
            CommandToken <T> token = new CommandToken <T>(Reader.GetSchemaTable());

            if (!CallBackDataSetters.TryGetValue(token, out Func <SqlDataReader, T> SetCallBackData))
            {
                CallBackDataSetters.Add(token, SetCallBackData = token.GenerateCallBackDataSetter());
            }

            Reader.Read();

            return(SetCallBackData(Reader));
        }