Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / schema / ChameleonKey.cs / 1305376 / ChameleonKey.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml.Schema { using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Xml.Serialization; // Case insensitive file name key for use in a hashtable. internal class ChameleonKey { internal string targetNS; internal Uri chameleonLocation; // Original schema (used for reference equality only) // stored only when the chameleonLocation is an empty URI in which case the location // is not a good enough identification of the schema internal XmlSchema originalSchema; int hashCode; ////// Creates a new chameleon key - an identification for a chameleon schema instance /// /// The target namespace of the instance of the chameleon schema /// The original (chameleon) schema (the one without the target namespace). /// This is used to get the location (base uri) and to identify the schema. public ChameleonKey(string ns, XmlSchema originalSchema) { targetNS = ns; chameleonLocation = originalSchema.BaseUri; if (chameleonLocation.OriginalString.Length == 0) { // Only store the original schema when the location is empty URI // by doing this we effectively allow multiple chameleon schemas for the same target namespace // and URI, but that only makes sense for empty URI (not specified) this.originalSchema = originalSchema; } } public override int GetHashCode() { if (hashCode == 0) { hashCode = targetNS.GetHashCode() + chameleonLocation.GetHashCode() + (originalSchema == null ? 0 : originalSchema.GetHashCode()); } return hashCode; } public override bool Equals(object obj) { if (Ref.ReferenceEquals(this,obj)) { return true; } ChameleonKey cKey = obj as ChameleonKey; if (cKey != null) { // We want to compare the target NS and the schema location. // If the location is empty (but only then) we also want to compare the original schema instance. // As noted above the originalSchema is null if the chameleonLocation is non-empty. As a result we // can simply compare the reference to the original schema always (regardless of the schemalocation). Debug.Assert((chameleonLocation.OriginalString.Length == 0 && originalSchema != null) || (chameleonLocation.OriginalString.Length != 0 && originalSchema == null)); return this.targetNS.Equals(cKey.targetNS) && this.chameleonLocation.Equals(cKey.chameleonLocation) && Ref.ReferenceEquals(originalSchema, cKey.originalSchema); } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml.Schema { using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Xml.Serialization; // Case insensitive file name key for use in a hashtable. internal class ChameleonKey { internal string targetNS; internal Uri chameleonLocation; // Original schema (used for reference equality only) // stored only when the chameleonLocation is an empty URI in which case the location // is not a good enough identification of the schema internal XmlSchema originalSchema; int hashCode; ////// Creates a new chameleon key - an identification for a chameleon schema instance /// /// The target namespace of the instance of the chameleon schema /// The original (chameleon) schema (the one without the target namespace). /// This is used to get the location (base uri) and to identify the schema. public ChameleonKey(string ns, XmlSchema originalSchema) { targetNS = ns; chameleonLocation = originalSchema.BaseUri; if (chameleonLocation.OriginalString.Length == 0) { // Only store the original schema when the location is empty URI // by doing this we effectively allow multiple chameleon schemas for the same target namespace // and URI, but that only makes sense for empty URI (not specified) this.originalSchema = originalSchema; } } public override int GetHashCode() { if (hashCode == 0) { hashCode = targetNS.GetHashCode() + chameleonLocation.GetHashCode() + (originalSchema == null ? 0 : originalSchema.GetHashCode()); } return hashCode; } public override bool Equals(object obj) { if (Ref.ReferenceEquals(this,obj)) { return true; } ChameleonKey cKey = obj as ChameleonKey; if (cKey != null) { // We want to compare the target NS and the schema location. // If the location is empty (but only then) we also want to compare the original schema instance. // As noted above the originalSchema is null if the chameleonLocation is non-empty. As a result we // can simply compare the reference to the original schema always (regardless of the schemalocation). Debug.Assert((chameleonLocation.OriginalString.Length == 0 && originalSchema != null) || (chameleonLocation.OriginalString.Length != 0 && originalSchema == null)); return this.targetNS.Equals(cKey.targetNS) && this.chameleonLocation.Equals(cKey.chameleonLocation) && Ref.ReferenceEquals(originalSchema, cKey.originalSchema); } return false; } } } // 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
- ResourceProviderFactory.cs
- NumericUpDownAccelerationCollection.cs
- ValidationSummary.cs
- InfoCardMetadataExchangeClient.cs
- Token.cs
- SettingsProperty.cs
- StreamReader.cs
- AnnotationComponentChooser.cs
- ToggleButtonAutomationPeer.cs
- Point3DAnimationUsingKeyFrames.cs
- AccessViolationException.cs
- PKCS1MaskGenerationMethod.cs
- HuffCodec.cs
- GlobalEventManager.cs
- RectAnimationClockResource.cs
- MouseGestureValueSerializer.cs
- ProxyWebPart.cs
- TextFormatterImp.cs
- BrowserTree.cs
- RegularExpressionValidator.cs
- ExpressionLexer.cs
- LowerCaseStringConverter.cs
- Brush.cs
- QuadraticBezierSegment.cs
- ComNativeDescriptor.cs
- HttpListenerResponse.cs
- TemplateBindingExpression.cs
- ProfileEventArgs.cs
- DataGridViewRowsRemovedEventArgs.cs
- KnownColorTable.cs
- SecurityDescriptor.cs
- BackgroundWorker.cs
- XmlChildEnumerator.cs
- XmlSchemaAny.cs
- DescendantQuery.cs
- MobileControlsSectionHelper.cs
- WsdlWriter.cs
- ServerProtocol.cs
- DefaultTextStore.cs
- QilValidationVisitor.cs
- WindowsGraphicsCacheManager.cs
- NopReturnReader.cs
- DelayedRegex.cs
- XamlPathDataSerializer.cs
- GrammarBuilderBase.cs
- WsatServiceAddress.cs
- SupportsEventValidationAttribute.cs
- _FtpControlStream.cs
- TableFieldsEditor.cs
- XPathNavigatorReader.cs
- AppliedDeviceFiltersEditor.cs
- AtomEntry.cs
- SQLBytes.cs
- ParamArrayAttribute.cs
- MetadataPropertyCollection.cs
- WebPartConnectVerb.cs
- MatrixTransform.cs
- ArgIterator.cs
- SerializationStore.cs
- WebPartTransformerCollection.cs
- SynchronizedInputAdaptor.cs
- RuleProcessor.cs
- DES.cs
- Vector3DAnimationUsingKeyFrames.cs
- DependencyPropertyChangedEventArgs.cs
- RenderingEventArgs.cs
- odbcmetadatacollectionnames.cs
- RedirectionProxy.cs
- TextEditorLists.cs
- PEFileEvidenceFactory.cs
- SchemaTableColumn.cs
- PanelStyle.cs
- BitmapSizeOptions.cs
- TrustManager.cs
- XmlAggregates.cs
- NavigatorOutput.cs
- WebScriptMetadataMessage.cs
- WebPartActionVerb.cs
- ArraySet.cs
- TypeUnloadedException.cs
- TokenizerHelper.cs
- DelegateHelpers.Generated.cs
- RIPEMD160Managed.cs
- httpstaticobjectscollection.cs
- GlyphRunDrawing.cs
- UIPropertyMetadata.cs
- FamilyCollection.cs
- CryptoApi.cs
- WebPartCancelEventArgs.cs
- DataBindingExpressionBuilder.cs
- ReadOnlyMetadataCollection.cs
- dbenumerator.cs
- DocumentGridPage.cs
- PaintEvent.cs
- HtmlElementErrorEventArgs.cs
- XmlDesigner.cs
- UnmanagedMemoryStreamWrapper.cs
- BitmapImage.cs
- DocumentViewerHelper.cs
- PreloadHost.cs