Example #1
0
        /// <summary>
        /// Random access to values by their name.
        /// </summary>
        /// <remarks>
        /// This method works only if a CSV header has been previously read or written
        /// with the associated <see cref="CsvFile"/> class.
        /// </remarks>

        public string this[string sColName]
        {
            get
            {
                if (sColName == null)
                {
                    throw new ArgumentNullException("sColName", "ArgumentNullException: sColName");
                }
                if (sColName == "")
                {
                    throw new ArgumentException("sColName", "sColName");
                }
                if (m_aCsvFile == null)
                {
                    throw new InvalidOperationException("m_aCsvFile");
                }

                int nIndex = m_aCsvFile.IndexOf(sColName);
                return(nIndex < 0 ? null : m_vValues[nIndex]);
            }
            set
            {
                if (sColName == null)
                {
                    throw new ArgumentNullException("sColName", "ArgumentNullException: sColName");
                }
                if (sColName == "")
                {
                    throw new ArgumentException("sColName", "sColName");
                }
                if (m_aCsvFile == null)
                {
                    throw new InvalidOperationException("m_aCsvFile");
                }

                int nIndex = m_aCsvFile.IndexOf(sColName);
                if (nIndex < 0)
                {
                    throw new ApplicationException("CsvValues");
                }
                m_vValues[nIndex] = value;
            }
        }