// Copyright 2009-2022 Josh Close // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0. // See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0. // https://github.com/JoshClose/CsvHelper using System.Collections; using System.Collections.Generic; namespace CsvHelper.Configuration { /// /// A collection that holds member names. /// public class MemberNameCollection : IEnumerable { private readonly List names = new List(); /// /// Gets the name at the given index. If a prefix is set, /// it will be prepended to the name. /// /// /// public string this[int index] { get { return Prefix + names[index]; } set { names[index] = value; } } /// /// Gets the prefix to use for each name. /// public string Prefix { get; set; } /// /// Gets the raw list of names without /// the prefix being prepended. /// public List Names => names; /// /// Gets the count. /// public int Count => names.Count; /// /// Adds the given name to the collection. /// /// The name to add. public void Add(string name) { names.Add(name); } /// /// Clears all names from the collection. /// public void Clear() { names.Clear(); } /// /// Adds a range of names to the collection. /// /// The range to add. public void AddRange(IEnumerable names) { this.names.AddRange(names); } /// /// Returns an enumerator that iterates through the collection. /// /// /// A that can be used to iterate through the collection. /// /// 1 public IEnumerator GetEnumerator() { for (var i = 0; i < names.Count; i++) { yield return this[i]; } } /// /// Returns an enumerator that iterates through a collection. /// /// /// An object that can be used to iterate through the collection. /// /// 2 IEnumerator IEnumerable.GetEnumerator() { return names.GetEnumerator(); } } }