Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- XhtmlBasicLiteralTextAdapter.cs
- CroppedBitmap.cs
- GenerateHelper.cs
- VisualStyleRenderer.cs
- ChangePassword.cs
- EncodingDataItem.cs
- SystemInfo.cs
- PrintControllerWithStatusDialog.cs
- SqlParameterCollection.cs
- AppDomainInfo.cs
- SettingsContext.cs
- WebConfigurationHost.cs
- CodeMemberProperty.cs
- TabControlCancelEvent.cs
- CharEntityEncoderFallback.cs
- Message.cs
- NonDualMessageSecurityOverHttpElement.cs
- DashStyle.cs
- EncoderNLS.cs
- CDSsyncETWBCLProvider.cs
- BaseCollection.cs
- SizeConverter.cs
- Operator.cs
- _ProxyRegBlob.cs
- _FixedSizeReader.cs
- RtType.cs
- GotoExpression.cs
- SHA256CryptoServiceProvider.cs
- EventLogRecord.cs
- WebPartZoneBase.cs
- FileUtil.cs
- MetadataArtifactLoader.cs
- ContourSegment.cs
- MenuCommands.cs
- validationstate.cs
- ZoomingMessageFilter.cs
- DirectoryObjectSecurity.cs
- DragEvent.cs
- GeometryModel3D.cs
- CalendarSelectionChangedEventArgs.cs
- Ray3DHitTestResult.cs
- FormsAuthenticationModule.cs
- StreamedFramingRequestChannel.cs
- LabelEditEvent.cs
- GenericXmlSecurityTokenAuthenticator.cs
- NonSerializedAttribute.cs
- SafeTimerHandle.cs
- DbDataReader.cs
- LogLogRecordEnumerator.cs
- PrintDialog.cs
- CategoryNameCollection.cs
- WindowsListViewItemStartMenu.cs
- CommonEndpointBehaviorElement.cs
- SQLInt64.cs
- SchemaElementDecl.cs
- DateTimeStorage.cs
- SpAudioStreamWrapper.cs
- MonikerProxyAttribute.cs
- DataSourceExpressionCollection.cs
- BooleanExpr.cs
- CompiledIdentityConstraint.cs
- MergeLocalizationDirectives.cs
- IndependentlyAnimatedPropertyMetadata.cs
- CallId.cs
- SeekStoryboard.cs
- BuildResult.cs
- BamlVersionHeader.cs
- DescendantOverDescendantQuery.cs
- CustomAttributeBuilder.cs
- RegularExpressionValidator.cs
- DescendantOverDescendantQuery.cs
- UnsafeNativeMethods.cs
- MailMessageEventArgs.cs
- BamlResourceContent.cs
- SmiEventSink_DeferedProcessing.cs
- DataGridViewRowsRemovedEventArgs.cs
- ScriptingWebServicesSectionGroup.cs
- LambdaCompiler.Logical.cs
- DefaultMemberAttribute.cs
- ColorConvertedBitmap.cs
- MobileControlsSectionHandler.cs
- DropDownList.cs
- UserNameSecurityToken.cs
- BitmapPalette.cs
- XsltArgumentList.cs
- RunWorkerCompletedEventArgs.cs
- Paragraph.cs
- Lease.cs
- SqlCacheDependencySection.cs
- SchemaObjectWriter.cs
- SoapCodeExporter.cs
- BamlWriter.cs
- ItemCollectionEditor.cs
- EpmContentDeSerializerBase.cs
- DateTimeConstantAttribute.cs
- ConvertersCollection.cs
- ScriptingProfileServiceSection.cs
- MatchingStyle.cs
- XmlSigningNodeWriter.cs
- ToolZoneDesigner.cs