Exemple #1
0
        /// <summary>
        /// Return the value in the column with the given name.
        ///
        /// Will throw if no column with that name exists .  Use <see cref="TryGetValue(string, out Value)"/> for non-throwing gets.
        /// </summary>
        public             Value this[string columnName]
        {
            get
            {
                long translatedColumnIndex;
                if (!Parent.TryLookupTranslatedColumnIndex(columnName, out translatedColumnIndex))
                {
                    throw new KeyNotFoundException($"Could not find column with name \"{columnName}\"");
                }

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

                    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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns the column with the given name.
        ///
        /// Throws if no column has the given name.
        /// </summary>
        public      Column this[string columnName]
        {
            get
            {
                long translatedIndex;
                if (!Parent.TryLookupTranslatedColumnIndex(columnName, out translatedIndex))
                {
                    throw new KeyNotFoundException($"Could not find column with name \"{columnName}\"");
                }

                return(new Column(Parent, translatedIndex));
            }
        }