Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / QIL / SubstitutionList.cs
blob32868e6a185c514490b4b51d85f716668d57122f
1 //------------------------------------------------------------------------------
2 // <copyright file="SubstitutionList.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7 using System;
8 using System.Collections;
9 using System.Diagnostics;
11 namespace System.Xml.Xsl.Qil {
13 /// <summary>
14 /// Data structure for use in CloneAndReplace
15 /// </summary>
16 /// <remarks>Isolates the many QilNode classes from changes in
17 /// the underlying data structure.</remarks>
18 internal sealed class SubstitutionList {
19 //
20 private ArrayList s;
22 public SubstitutionList() {
23 this.s = new ArrayList(4);
26 /// <summary>
27 /// Add a substituion pair
28 /// </summary>
29 /// <param name="find">a node to be replaced</param>
30 /// <param name="replace">its replacement</param>
31 public void AddSubstitutionPair(QilNode find, QilNode replace) {
32 s.Add(find);
33 s.Add(replace);
36 /// <summary>
37 /// Remove the last a substituion pair
38 /// </summary>
39 public void RemoveLastSubstitutionPair() {
40 s.RemoveRange(s.Count - 2, 2);
43 /// <summary>
44 /// Remove the last N substitution pairs
45 /// </summary>
46 public void RemoveLastNSubstitutionPairs(int n) {
47 Debug.Assert(n >= 0, "n must be nonnegative");
48 if (n > 0) {
49 n *= 2;
50 s.RemoveRange(s.Count - n, n);
54 /// <summary>
55 /// Find the replacement for a node
56 /// </summary>
57 /// <param name="n">the node to replace</param>
58 /// <returns>null if no replacement is found</returns>
59 public QilNode FindReplacement(QilNode n) {
60 Debug.Assert(s.Count % 2 == 0);
61 for (int i = s.Count-2; i >= 0; i-=2)
62 if (s[i] == n)
63 return (QilNode)s[i+1];
64 return null;