Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / XmlUtils / System / Xml / Xsl / Runtime / DocumentOrderComparer.cs / 1 / DocumentOrderComparer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Xml.XPath; using System.Diagnostics; namespace System.Xml.Xsl.Runtime { ////// IComparer implementation that orders navigators based on ComparePosition. When ComparePosition returns /// XmlNodeOrder.Unknown, a stable order between documents is maintained by an ordered list mapping each root node /// to an ordering index. /// internal class DocumentOrderComparer : IComparer{ private List roots; /// /// Return: /// -1 if navThis is positioned before navThat /// 0 if navThis has the same position as navThat /// 1 if navThis is positioned after navThat /// public int Compare(XPathNavigator navThis, XPathNavigator navThat) { switch (navThis.ComparePosition(navThat)) { case XmlNodeOrder.Before: return -1; case XmlNodeOrder.Same: return 0; case XmlNodeOrder.After: return 1; } // Use this.roots to impose stable ordering if (this.roots == null) this.roots = new List(); Debug.Assert(GetDocumentIndex(navThis) != GetDocumentIndex(navThat)); return GetDocumentIndex(navThis) < GetDocumentIndex(navThat) ? -1 : 1; } /// /// Map navigator's document to a unique index. /// When consecutive calls are made to GetIndexOfNavigator for navThis and navThat, it is not possible /// for them to return the same index. navThis compared to navThat is always XmlNodeOrder.Unknown. /// Therefore, no matter where navThis is inserted in the list, navThat will never be inserted just /// before navThis, and therefore will never have the same index. /// public int GetDocumentIndex(XPathNavigator nav) { XPathNavigator navRoot; // Use this.roots to impose stable ordering if (this.roots == null) this.roots = new List(); // Position navigator to root navRoot = nav.Clone(); navRoot.MoveToRoot(); for (int idx = 0; idx < this.roots.Count; idx++) { if (navRoot.IsSamePosition(this.roots[idx])) { // navigator's document was previously mapped to a unique index return idx; } } // Add navigator to this.roots mapping this.roots.Add(navRoot); return this.roots.Count - 1; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Xml.XPath; using System.Diagnostics; namespace System.Xml.Xsl.Runtime { ////// IComparer implementation that orders navigators based on ComparePosition. When ComparePosition returns /// XmlNodeOrder.Unknown, a stable order between documents is maintained by an ordered list mapping each root node /// to an ordering index. /// internal class DocumentOrderComparer : IComparer{ private List roots; /// /// Return: /// -1 if navThis is positioned before navThat /// 0 if navThis has the same position as navThat /// 1 if navThis is positioned after navThat /// public int Compare(XPathNavigator navThis, XPathNavigator navThat) { switch (navThis.ComparePosition(navThat)) { case XmlNodeOrder.Before: return -1; case XmlNodeOrder.Same: return 0; case XmlNodeOrder.After: return 1; } // Use this.roots to impose stable ordering if (this.roots == null) this.roots = new List(); Debug.Assert(GetDocumentIndex(navThis) != GetDocumentIndex(navThat)); return GetDocumentIndex(navThis) < GetDocumentIndex(navThat) ? -1 : 1; } /// /// Map navigator's document to a unique index. /// When consecutive calls are made to GetIndexOfNavigator for navThis and navThat, it is not possible /// for them to return the same index. navThis compared to navThat is always XmlNodeOrder.Unknown. /// Therefore, no matter where navThis is inserted in the list, navThat will never be inserted just /// before navThis, and therefore will never have the same index. /// public int GetDocumentIndex(XPathNavigator nav) { XPathNavigator navRoot; // Use this.roots to impose stable ordering if (this.roots == null) this.roots = new List(); // Position navigator to root navRoot = nav.Clone(); navRoot.MoveToRoot(); for (int idx = 0; idx < this.roots.Count; idx++) { if (navRoot.IsSamePosition(this.roots[idx])) { // navigator's document was previously mapped to a unique index return idx; } } // Add navigator to this.roots mapping this.roots.Add(navRoot); return this.roots.Count - 1; } } } // 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
- HtmlControlPersistable.cs
- RuleInfoComparer.cs
- DataBindingHandlerAttribute.cs
- SingleObjectCollection.cs
- ReferentialConstraint.cs
- SafeThemeHandle.cs
- ProfileProvider.cs
- EntityCollectionChangedParams.cs
- DataRelation.cs
- WebPartCancelEventArgs.cs
- UserControlAutomationPeer.cs
- FixedBufferAttribute.cs
- BoolExpressionVisitors.cs
- DocumentSequence.cs
- CodeAccessSecurityEngine.cs
- ClientScriptItem.cs
- ILGenerator.cs
- StylusPointPropertyInfo.cs
- DialogBaseForm.cs
- ModulesEntry.cs
- ModuleElement.cs
- WaitForChangedResult.cs
- QueryOutputWriter.cs
- WindowsHyperlink.cs
- HandoffBehavior.cs
- EntitySqlException.cs
- ListInitExpression.cs
- ReadOnlyNameValueCollection.cs
- WSUtilitySpecificationVersion.cs
- DataGridViewDataErrorEventArgs.cs
- BitmapImage.cs
- ToolStripDropDownItemDesigner.cs
- Visual3DCollection.cs
- TakeOrSkipQueryOperator.cs
- XmlCharacterData.cs
- ImageInfo.cs
- ChangePasswordAutoFormat.cs
- TrustManagerMoreInformation.cs
- PrinterResolution.cs
- XhtmlBasicCommandAdapter.cs
- TrustManagerPromptUI.cs
- HeaderedContentControl.cs
- _NtlmClient.cs
- FixedDSBuilder.cs
- BitmapMetadataBlob.cs
- columnmapfactory.cs
- EncoderParameters.cs
- Canvas.cs
- LocationSectionRecord.cs
- httpstaticobjectscollection.cs
- BuiltInExpr.cs
- CustomCategoryAttribute.cs
- ListViewItemEventArgs.cs
- RelationshipEnd.cs
- VirtualizingPanel.cs
- Vector3DValueSerializer.cs
- ContractInstanceProvider.cs
- RegistrationServices.cs
- DateTimeFormatInfoScanner.cs
- TemplatePagerField.cs
- MenuTracker.cs
- ServiceThrottlingElement.cs
- codemethodreferenceexpression.cs
- cache.cs
- InvalidateEvent.cs
- ImageConverter.cs
- LinqDataSourceContextData.cs
- SoundPlayer.cs
- srgsitem.cs
- RenderDataDrawingContext.cs
- Helpers.cs
- TabControlToolboxItem.cs
- InkPresenter.cs
- PolicyLevel.cs
- NullableDecimalMinMaxAggregationOperator.cs
- LayoutEditorPart.cs
- ResourceLoader.cs
- WorkflowRuntime.cs
- DbUpdateCommandTree.cs
- TextServicesDisplayAttributePropertyRanges.cs
- KeyedCollection.cs
- RoleService.cs
- Delegate.cs
- Size.cs
- SerialStream.cs
- EventItfInfo.cs
- TransactionManager.cs
- ForeignKeyConstraint.cs
- OdbcDataAdapter.cs
- GetPageCompletedEventArgs.cs
- ConditionalAttribute.cs
- KeysConverter.cs
- CompositeCollectionView.cs
- XmlIgnoreAttribute.cs
- NavigateEvent.cs
- ObjectStorage.cs
- VisualStyleElement.cs
- Pts.cs
- RegularExpressionValidator.cs
- CompModSwitches.cs