blob: fb9db4afa11dd998a2bf7e9704784803835f40ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// 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
{
/// <summary>
/// A collection that holds member names.
/// </summary>
public class MemberNameCollection : IEnumerable<string>
{
private readonly List<string> names = new List<string>();
/// <summary>
/// Gets the name at the given index. If a prefix is set,
/// it will be prepended to the name.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public string this[int index]
{
get { return Prefix + names[index]; }
set { names[index] = value; }
}
/// <summary>
/// Gets the prefix to use for each name.
/// </summary>
public string Prefix { get; set; }
/// <summary>
/// Gets the raw list of names without
/// the prefix being prepended.
/// </summary>
public List<string> Names => names;
/// <summary>
/// Gets the count.
/// </summary>
public int Count => names.Count;
/// <summary>
/// Adds the given name to the collection.
/// </summary>
/// <param name="name">The name to add.</param>
public void Add(string name)
{
names.Add(name);
}
/// <summary>
/// Clears all names from the collection.
/// </summary>
public void Clear()
{
names.Clear();
}
/// <summary>
/// Adds a range of names to the collection.
/// </summary>
/// <param name="names">The range to add.</param>
public void AddRange(IEnumerable<string> names)
{
this.names.AddRange(names);
}
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
/// </returns>
/// <filterpriority>1</filterpriority>
public IEnumerator<string> GetEnumerator()
{
for (var i = 0; i < names.Count; i++)
{
yield return this[i];
}
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
/// </returns>
/// <filterpriority>2</filterpriority>
IEnumerator IEnumerable.GetEnumerator()
{
return names.GetEnumerator();
}
}
}
|