/// <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 rowIndex] { get { var translatedRowIndex = Parent.TranslateIndex(rowIndex); Value value; if (!Parent.TryGetValueTranslated(translatedRowIndex, TranslatedColumnIndex, out value)) { long minLegal; long maxLegal; switch (Parent.Basis) { case BasisType.One: minLegal = 1; maxLegal = Parent.Metadata.NumRows; break; case BasisType.Zero: minLegal = 0; maxLegal = Parent.Metadata.NumRows - 1; break; default: throw new InvalidOperationException($"Unexpected Basis: {Parent.Basis}"); } throw new ArgumentOutOfRangeException($"Row index out of range, valid between [{minLegal}, {maxLegal}] found {rowIndex}"); } return(value); } }
/// <summary> /// <see cref="System.Collections.Generic.IEnumerator{T}"/> /// </summary> public bool MoveNext() { Index++; Value value; if (!Parent.TryGetValueTranslated(Index, TranslatedColumnIndex, out value)) { return(false); } Current = value; return(true); }
/// <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); } }