Exemple #1
0
        /// <summary>
        /// Converts this column to an array of the specified type.
        ///
        /// Throws if the column cannot be coerced to the given type, or cannot fit in an array.
        /// </summary>
        public              T[] ToArray <T>()
        {
            if (Length > int.MaxValue)
            {
                throw new InvalidOperationException($"Length ({Length:N0}) greater that int.MaxValue, can't possibly fit in a single array");
            }

            T[] ret = null;
            GetRange(Parent.UntranslateIndex(0), (int)Length, ref ret);
            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// Return the value at the given index.
        ///
        /// Will throw if the index is out of bounds.  Use <see cref="TryGetValue(long, out Value)"/> for non-throwing gets.
        /// </summary>
        public             Value this[long columnIndex]
        {
            get
            {
                var translatedColumnIndex = Parent.TranslateIndex(columnIndex);

                Value value;
                if (!Parent.TryGetValueTranslated(TranslatedRowIndex, translatedColumnIndex, out value))
                {
                    var rowIndex = Parent.UntranslateIndex(TranslatedRowIndex);

                    long minRowIx, minColIx, maxRowIx, maxColIx;
                    switch (Parent.Basis)
                    {
                    case BasisType.One:
                        minRowIx = 1;
                        maxRowIx = Parent.Metadata.NumRows;
                        minColIx = 1;
                        maxColIx = Parent.Metadata.Columns.Length;
                        break;

                    case BasisType.Zero:
                        minRowIx = 0;
                        maxRowIx = Parent.Metadata.NumRows - 1;
                        minColIx = 0;
                        maxColIx = Parent.Metadata.Columns.Length - 1;
                        break;

                    default: throw new InvalidOperationException($"Unexpected Basis: {Parent.Basis}");
                    }

                    throw new ArgumentOutOfRangeException($"Address out of range, legal range is [{minRowIx}, {minColIx}] - [{maxRowIx}, {maxColIx}], found [{rowIndex}, {columnIndex}]");
                }

                return(value);
            }
        }