コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <exception cref="ArgumentNullException"><paramref name="row"/> is null.</exception>
        public override void Add(CsvDataRow row)
        {
            CheckRow(row);

            var nrow = TryCastCsvDataRow(row);

            InternalInsert(nrow, Count);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="row"/> is null.</exception>
        public override bool Remove(CsvDataRow row)
        {
            CheckRow(row);

            var nrow = TryCastCsvDataRow(row);

            return(InternalRemove(nrow));
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CsvDataRow NewRow(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var row = CsvDataRow.CreateInternal(_csvDataType, this, name);

            return(row);
        }
コード例 #4
0
        // Tries to cast specified CsvDataRow to CsvDataRow<TCsvData> if it fails,
        // it throws an ArgumentException.
        private static CsvDataRow <TCsvData> TryCastCsvDataRow(CsvDataRow row)
        {
            var nrow = row as CsvDataRow <TCsvData>;

            if (nrow == null)
            {
                throw new ArgumentException("Unable to explicitly cast row to " + typeof(CsvDataRow <TCsvData>) + ".", nameof(row));
            }

            return(nrow);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <param name="index"></param>
        public void InsertAt(CsvDataRow <TCsvData> row, int index)
        {
            CheckRow(row);

            if (index < 0 || index > Count)
            {
                throw new ArgumentOutOfRangeException("Index must be non-negative and less or equal the number of item in the collection.", nameof(index));
            }

            InternalInsert(row, index);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="row"/> is null.</exception>
        public bool Contains(CsvDataRow <TCsvData> row)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            if (row.Table != Table || row.Ref != null)
            {
                return(false);
            }

            return(_rows.Contains(row));
        }
コード例 #7
0
 private void CheckRow(CsvDataRow row)
 {
     if (row == null)
     {
         throw new ArgumentNullException(nameof(row));
     }
     if (row.Table != Table)
     {
         throw new ArgumentException("Row belongs to another table.", nameof(row));
     }
     if (row.Ref != null)
     {
         throw new ArgumentException("Row already belongs to this table.", nameof(row));
     }
 }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="row"/> is null.</exception>
        public override bool Contains(CsvDataRow row)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            if (row.Table != Table || row.Ref != null)
            {
                return(false);
            }

            var nrow = TryCastCsvDataRow(row);

            return(_rows.Contains(nrow));
        }
コード例 #9
0
        private void InternalInsert(CsvDataRow <TCsvData> row, int index)
        {
            Debug.Assert(row.Name != null);
            // Add the row name to the dictionary which maps row names to row indexes.
            // And ignore rows with name having duplicates.
            if (!_name2index.ContainsKey(row.Name))
            {
                _name2index.Add(row.Name, index);
            }

            row._ref = new CsvDataRowRef <TCsvData>(Table.KindID, index);
            _rows.Insert(index, row);

            // Update the Ref of CsvDataRow after the index where the insert occurred.
            for (; index < _rows.Count; index++)
            {
                _rows[index]._ref = new CsvDataRowRef <TCsvData>(Table.KindID, index);
                _rows[index].UpdateRefs();
            }
        }
コード例 #10
0
        private bool InternalRemove(CsvDataRow <TCsvData> row)
        {
            var index = _rows.IndexOf(row);

            if (index == -1)
            {
                return(false);
            }

            _rows.RemoveAt(index);
            row._table = null;
            row._ref   = null;
            row.UpdateRefs();

            for (; index < _rows.Count; index++)
            {
                _rows[index]._ref = new CsvDataRowRef <TCsvData>(Table.KindID, index);
                _rows[index].UpdateRefs();
            }
            return(true);
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <exception cref="ArgumentNullException"><paramref name="row"/> is null.</exception>
        public void Add(CsvDataRow <TCsvData> row)
        {
            CheckRow(row);

            InternalInsert(row, Count);
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="row"/> is null.</exception>
        public bool Remove(CsvDataRow <TCsvData> row)
        {
            CheckRow(row);

            return(InternalRemove(row));
        }