mscorlib(4.0.0.0) API with additions
MatchCollection.cs
1 using System.Collections;
2 
4 {
7  [global::__DynamicallyInvokable]
9  {
10  internal Regex _regex;
11 
12  internal ArrayList _matches;
13 
14  internal bool _done;
15 
16  internal string _input;
17 
18  internal int _beginning;
19 
20  internal int _length;
21 
22  internal int _startat;
23 
24  internal int _prevlen;
25 
26  private static int infinite = int.MaxValue;
27 
31  [global::__DynamicallyInvokable]
32  public int Count
33  {
34  [global::__DynamicallyInvokable]
35  get
36  {
37  if (_done)
38  {
39  return _matches.Count;
40  }
41  GetMatch(infinite);
42  return _matches.Count;
43  }
44  }
45 
48  public object SyncRoot => this;
49 
53  public bool IsSynchronized => false;
54 
58  public bool IsReadOnly => true;
59 
66  [global::__DynamicallyInvokable]
67  public virtual Match this[int i]
68  {
69  [global::__DynamicallyInvokable]
70  get
71  {
72  Match match = GetMatch(i);
73  if (match == null)
74  {
75  throw new ArgumentOutOfRangeException("i");
76  }
77  return match;
78  }
79  }
80 
81  internal MatchCollection(Regex regex, string input, int beginning, int length, int startat)
82  {
83  if (startat < 0 || startat > input.Length)
84  {
85  throw new ArgumentOutOfRangeException("startat", SR.GetString("BeginIndexNotNegative"));
86  }
87  _regex = regex;
88  _input = input;
89  _beginning = beginning;
90  _length = length;
91  _startat = startat;
92  _prevlen = -1;
93  _matches = new ArrayList();
94  _done = false;
95  }
96 
97  internal Match GetMatch(int i)
98  {
99  if (i < 0)
100  {
101  return null;
102  }
103  if (_matches.Count > i)
104  {
105  return (Match)_matches[i];
106  }
107  if (_done)
108  {
109  return null;
110  }
111  Match match;
112  do
113  {
114  match = _regex.Run(quick: false, _prevlen, _input, _beginning, _length, _startat);
115  if (!match.Success)
116  {
117  _done = true;
118  return null;
119  }
120  _matches.Add(match);
121  _prevlen = match._length;
122  _startat = match._textpos;
123  }
124  while (_matches.Count <= i);
125  return match;
126  }
127 
137  public void CopyTo(Array array, int arrayIndex)
138  {
139  if (array != null && array.Rank != 1)
140  {
141  throw new ArgumentException(SR.GetString("Arg_RankMultiDimNotSupported"));
142  }
143  int count = Count;
144  try
145  {
146  _matches.CopyTo(array, arrayIndex);
147  }
148  catch (ArrayTypeMismatchException innerException)
149  {
150  throw new ArgumentException(SR.GetString("Arg_InvalidArrayType"), innerException);
151  }
152  }
153 
157  [global::__DynamicallyInvokable]
159  {
160  return new MatchEnumerator(this);
161  }
162  }
163 }
bool IsReadOnly
Gets a value that indicates whether the collection is read only.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
object SyncRoot
Gets an object that can be used to synchronize access to the collection.
bool IsSynchronized
Gets a value indicating whether access to the collection is synchronized (thread-safe).
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
IEnumerator GetEnumerator()
Provides an enumerator that iterates through the collection.
The exception that is thrown when an attempt is made to store an element of the wrong type within an ...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
virtual void CopyTo(Array array)
Copies the entire T:System.Collections.ArrayList to a compatible one-dimensional T:System....
Definition: ArrayList.cs:2516
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
Represents the results from a single regular expression match.
Definition: Match.cs:8
The exception that is thrown when one of the arguments provided to a method is not valid.
Specifies that the class can be serialized.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
void CopyTo(Array array, int arrayIndex)
Copies all the elements of the collection to the given array starting at the given index.
Represents an immutable regular expression.To browse the .NET Framework source code for this type,...
Definition: Regex.cs:16
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14
Represents the set of successful matches found by iteratively applying a regular expression pattern t...