1 //------------------------------------------------------------------------------
2 // <copyright file="SubstitutionList.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System
.Collections
;
9 using System
.Diagnostics
;
11 namespace System
.Xml
.Xsl
.Qil
{
14 /// Data structure for use in CloneAndReplace
16 /// <remarks>Isolates the many QilNode classes from changes in
17 /// the underlying data structure.</remarks>
18 internal sealed class SubstitutionList
{
22 public SubstitutionList() {
23 this.s
= new ArrayList(4);
27 /// Add a substituion pair
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
) {
37 /// Remove the last a substituion pair
39 public void RemoveLastSubstitutionPair() {
40 s
.RemoveRange(s
.Count
- 2, 2);
44 /// Remove the last N substitution pairs
46 public void RemoveLastNSubstitutionPairs(int n
) {
47 Debug
.Assert(n
>= 0, "n must be nonnegative");
50 s
.RemoveRange(s
.Count
- n
, n
);
55 /// Find the replacement for a node
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)
63 return (QilNode
)s
[i
+1];