Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / XmlUtils / System / Xml / Xsl / QIL / QilCloneVisitor.cs / 1 / 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
- StorageEndPropertyMapping.cs
- EdmItemError.cs
- ActionNotSupportedException.cs
- BufferBuilder.cs
- XmlAttributeProperties.cs
- MulticastIPAddressInformationCollection.cs
- Matrix3DValueSerializer.cs
- IndentedWriter.cs
- TabControl.cs
- ContainerUIElement3D.cs
- DrawingContextWalker.cs
- TraceHandler.cs
- Scripts.cs
- CacheVirtualItemsEvent.cs
- MultiDataTrigger.cs
- AlignmentXValidation.cs
- XmlTypeAttribute.cs
- DynamicHyperLink.cs
- TabRenderer.cs
- TrustManager.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- UriSection.cs
- ProofTokenCryptoHandle.cs
- NamespaceExpr.cs
- DigestComparer.cs
- ConstraintStruct.cs
- thaishape.cs
- PageBuildProvider.cs
- DynamicControl.cs
- WebServiceReceive.cs
- TextInfo.cs
- HttpException.cs
- SqlException.cs
- FileAuthorizationModule.cs
- DesignerRegion.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- ipaddressinformationcollection.cs
- GridViewRowPresenterBase.cs
- UnmanagedMemoryStreamWrapper.cs
- RuntimeConfig.cs
- ControlParameter.cs
- COM2ExtendedBrowsingHandler.cs
- SecureStringHasher.cs
- EntityDataSourceChangedEventArgs.cs
- PasswordTextNavigator.cs
- IdleTimeoutMonitor.cs
- ForceCopyBuildProvider.cs
- ComboBox.cs
- HwndProxyElementProvider.cs
- FixedPage.cs
- LinearGradientBrush.cs
- DockAndAnchorLayout.cs
- SR.Designer.cs
- ResponseBodyWriter.cs
- SeverityFilter.cs
- GridErrorDlg.cs
- Partitioner.cs
- ForwardPositionQuery.cs
- PrePrepareMethodAttribute.cs
- UIElement3D.cs
- DecoderExceptionFallback.cs
- TextRangeEdit.cs
- HuffCodec.cs
- SafeViewOfFileHandle.cs
- EdmValidator.cs
- Dictionary.cs
- SymDocumentType.cs
- ItemsPanelTemplate.cs
- CrossAppDomainChannel.cs
- Types.cs
- FileAuthorizationModule.cs
- LabelEditEvent.cs
- CapiHashAlgorithm.cs
- IApplicationTrustManager.cs
- ResourceDisplayNameAttribute.cs
- DataQuery.cs
- HWStack.cs
- FormViewPagerRow.cs
- BitConverter.cs
- DataGridCheckBoxColumn.cs
- DesignerSerializerAttribute.cs
- StructuredTypeEmitter.cs
- ObjectDesignerDataSourceView.cs
- ComponentDispatcherThread.cs
- DataServiceRequestArgs.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- SafeLibraryHandle.cs
- WindowsRebar.cs
- ArraySegment.cs
- XmlUrlResolver.cs
- AsyncStreamReader.cs
- XmlLoader.cs
- RuleSettingsCollection.cs
- util.cs
- ComboBoxRenderer.cs
- OracleConnection.cs
- CharAnimationUsingKeyFrames.cs
- CompensationHandlingFilter.cs
- CodeIndexerExpression.cs
- CqlParserHelpers.cs