Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / XmlUtils / System / Xml / Xsl / QIL / QilCloneVisitor.cs / 1305376 / QilCloneVisitor.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Xml; using System.Xml.Xsl; namespace System.Xml.Xsl.Qil { // Create an exact replica of a QIL graph internal class QilCloneVisitor : QilScopedVisitor { private QilFactory fac; private SubstitutionList subs; //----------------------------------------------- // Constructors //----------------------------------------------- public QilCloneVisitor(QilFactory fac) : this(fac, new SubstitutionList()) { } public QilCloneVisitor(QilFactory fac, SubstitutionList subs) { this.fac = fac; this.subs = subs; } //----------------------------------------------- // Entry //----------------------------------------------- public QilNode Clone(QilNode node) { // Assume that iterator nodes at the top-level are references rather than definitions return VisitAssumeReference(node); } //----------------------------------------------- // QilVisitor overrides //----------------------------------------------- ////// Visit all children of "parent", replacing each child with a copy of each child. /// protected override QilNode Visit(QilNode oldNode) { QilNode newNode = null; if (oldNode == null) return null; // ShallowClone any nodes which have not yet been cloned if (oldNode is QilReference) { // Reference nodes may have been cloned previously and put into scope newNode = FindClonedReference(oldNode); } if (newNode == null) newNode = oldNode.ShallowClone(this.fac); return base.Visit(newNode); } ////// Visit all children of "parent", replacing each child with a copy of each child. /// protected override QilNode VisitChildren(QilNode parent) { // Visit children for (int i = 0; i < parent.Count; i++) { QilNode child = parent[i]; // If child is a reference, if (IsReference(parent, i)) { // Visit the reference and substitute its copy parent[i] = VisitReference(child); // If no substutition found, then use original child if (parent[i] == null) parent[i] = child; } else { // Otherwise, visit the node and substitute its copy parent[i] = Visit(child); } } return parent; } ////// If a cloned reference is in scope, replace "oldNode". Otherwise, return "oldNode". /// protected override QilNode VisitReference(QilNode oldNode) { QilNode newNode = FindClonedReference(oldNode); return base.VisitReference(newNode == null ? oldNode : newNode); } //----------------------------------------------- // QilScopedVisitor methods //----------------------------------------------- ////// Push node and its shallow clone onto the substitution list. /// protected override void BeginScope(QilNode node) { this.subs.AddSubstitutionPair(node, node.ShallowClone(this.fac)); } ////// Pop entry from substitution list. /// protected override void EndScope(QilNode node) { this.subs.RemoveLastSubstitutionPair(); } //----------------------------------------------- // QilCloneVisitor methods //----------------------------------------------- ////// Find the clone of an in-scope reference. /// protected QilNode FindClonedReference(QilNode node) { return this.subs.FindReplacement(node); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Xml; using System.Xml.Xsl; namespace System.Xml.Xsl.Qil { // Create an exact replica of a QIL graph internal class QilCloneVisitor : QilScopedVisitor { private QilFactory fac; private SubstitutionList subs; //----------------------------------------------- // Constructors //----------------------------------------------- public QilCloneVisitor(QilFactory fac) : this(fac, new SubstitutionList()) { } public QilCloneVisitor(QilFactory fac, SubstitutionList subs) { this.fac = fac; this.subs = subs; } //----------------------------------------------- // Entry //----------------------------------------------- public QilNode Clone(QilNode node) { // Assume that iterator nodes at the top-level are references rather than definitions return VisitAssumeReference(node); } //----------------------------------------------- // QilVisitor overrides //----------------------------------------------- ////// Visit all children of "parent", replacing each child with a copy of each child. /// protected override QilNode Visit(QilNode oldNode) { QilNode newNode = null; if (oldNode == null) return null; // ShallowClone any nodes which have not yet been cloned if (oldNode is QilReference) { // Reference nodes may have been cloned previously and put into scope newNode = FindClonedReference(oldNode); } if (newNode == null) newNode = oldNode.ShallowClone(this.fac); return base.Visit(newNode); } ////// Visit all children of "parent", replacing each child with a copy of each child. /// protected override QilNode VisitChildren(QilNode parent) { // Visit children for (int i = 0; i < parent.Count; i++) { QilNode child = parent[i]; // If child is a reference, if (IsReference(parent, i)) { // Visit the reference and substitute its copy parent[i] = VisitReference(child); // If no substutition found, then use original child if (parent[i] == null) parent[i] = child; } else { // Otherwise, visit the node and substitute its copy parent[i] = Visit(child); } } return parent; } ////// If a cloned reference is in scope, replace "oldNode". Otherwise, return "oldNode". /// protected override QilNode VisitReference(QilNode oldNode) { QilNode newNode = FindClonedReference(oldNode); return base.VisitReference(newNode == null ? oldNode : newNode); } //----------------------------------------------- // QilScopedVisitor methods //----------------------------------------------- ////// Push node and its shallow clone onto the substitution list. /// protected override void BeginScope(QilNode node) { this.subs.AddSubstitutionPair(node, node.ShallowClone(this.fac)); } ////// Pop entry from substitution list. /// protected override void EndScope(QilNode node) { this.subs.RemoveLastSubstitutionPair(); } //----------------------------------------------- // QilCloneVisitor methods //----------------------------------------------- ////// Find the clone of an in-scope reference. /// protected QilNode FindClonedReference(QilNode node) { return this.subs.FindReplacement(node); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ImageSource.cs
- SqlOuterApplyReducer.cs
- ServiceCredentialsSecurityTokenManager.cs
- CharKeyFrameCollection.cs
- OLEDB_Enum.cs
- DbTransaction.cs
- SQLMoneyStorage.cs
- CapabilitiesRule.cs
- WindowInteropHelper.cs
- SignedPkcs7.cs
- IndependentAnimationStorage.cs
- XmlSchemaAny.cs
- URLMembershipCondition.cs
- WebEventTraceProvider.cs
- TextAdaptor.cs
- HGlobalSafeHandle.cs
- ProgressBarAutomationPeer.cs
- SelectionPattern.cs
- WsatRegistrationHeader.cs
- DynamicActivityXamlReader.cs
- SecurityTokenException.cs
- SystemWebSectionGroup.cs
- _Win32.cs
- LogStream.cs
- X509CertificateChain.cs
- MemoryMappedViewAccessor.cs
- CodeSubDirectory.cs
- PageVisual.cs
- HtmlTextBoxAdapter.cs
- DeferredRunTextReference.cs
- BitmapSource.cs
- NestPullup.cs
- WebPart.cs
- WindowsScroll.cs
- LinqToSqlWrapper.cs
- BufferAllocator.cs
- EntityDataSourceStatementEditor.cs
- TextSelectionHighlightLayer.cs
- DBCommand.cs
- AppDomain.cs
- SqlDataSourceView.cs
- OnOperation.cs
- XPathParser.cs
- LinqDataSourceValidationException.cs
- PerformanceCounter.cs
- MarkupCompilePass1.cs
- MediaScriptCommandRoutedEventArgs.cs
- Error.cs
- ScaleTransform3D.cs
- AppSecurityManager.cs
- SourceSwitch.cs
- CodeAttachEventStatement.cs
- ParserHooks.cs
- SvcFileManager.cs
- CryptoApi.cs
- ResourceSet.cs
- TextParentUndoUnit.cs
- CompilerErrorCollection.cs
- XmlEntityReference.cs
- PostBackTrigger.cs
- shaperfactoryquerycachekey.cs
- NamedElement.cs
- ToolboxDataAttribute.cs
- AccessorTable.cs
- CharacterString.cs
- PathFigureCollection.cs
- PathTooLongException.cs
- Globals.cs
- PageCodeDomTreeGenerator.cs
- ComponentDispatcher.cs
- SafeSecurityHandles.cs
- SafePointer.cs
- BaseEntityWrapper.cs
- Command.cs
- List.cs
- ArrayElementGridEntry.cs
- XmlExceptionHelper.cs
- AlignmentXValidation.cs
- _NegotiateClient.cs
- compensatingcollection.cs
- WebSysDescriptionAttribute.cs
- DashStyles.cs
- CodeEventReferenceExpression.cs
- UrlPath.cs
- _NativeSSPI.cs
- SqlInfoMessageEvent.cs
- SchemaObjectWriter.cs
- DefaultSection.cs
- InputScopeManager.cs
- ListViewItem.cs
- CodeVariableDeclarationStatement.cs
- LinkButton.cs
- DocumentGridContextMenu.cs
- Rfc4050KeyFormatter.cs
- ImageDrawing.cs
- DesignTimeTemplateParser.cs
- RegexMatchCollection.cs
- QilInvoke.cs
- ElementAction.cs
- CreateParams.cs