Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / WeakReferenceKey.cs / 1305600 / WeakReferenceKey.cs
//---------------------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // This file defines a class that holds a weak reference to an object. It preserves the hashcode // of the object and is intended to be used as a key in hashtables or dictionaries. // //------------------------------------------------------------------------------------- using System; using MS.Internal; namespace MS.Internal.Utility { ////// Helper class that allows using a weak reference to an item as a key in a hash table. /// internal class WeakReferenceKey{ public WeakReferenceKey(T item) { Invariant.Assert(item != null); _item = new WeakReference(item); _hashCode = item.GetHashCode(); } public T Item { get { return (T)_item.Target; } } public override bool Equals(object o) { if (o == this) return true; WeakReferenceKey key = o as WeakReferenceKey ; if (key != null) { T item = this.Item; if (item == null) return false; // a stale key matches nothing (except itself) return this._hashCode == key._hashCode && Object.Equals(item, key.Item); } return false; } public override int GetHashCode() { return _hashCode; } private WeakReference _item; private int _hashCode; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------------------- // // // Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // This file defines a class that holds a weak reference to an object. It preserves the hashcode // of the object and is intended to be used as a key in hashtables or dictionaries. // //------------------------------------------------------------------------------------- using System; using MS.Internal; namespace MS.Internal.Utility { ////// Helper class that allows using a weak reference to an item as a key in a hash table. /// internal class WeakReferenceKey{ public WeakReferenceKey(T item) { Invariant.Assert(item != null); _item = new WeakReference(item); _hashCode = item.GetHashCode(); } public T Item { get { return (T)_item.Target; } } public override bool Equals(object o) { if (o == this) return true; WeakReferenceKey key = o as WeakReferenceKey ; if (key != null) { T item = this.Item; if (item == null) return false; // a stale key matches nothing (except itself) return this._hashCode == key._hashCode && Object.Equals(item, key.Item); } return false; } public override int GetHashCode() { return _hashCode; } private WeakReference _item; private int _hashCode; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TransformerInfoCollection.cs
- XmlAttributeCollection.cs
- FontFamilyValueSerializer.cs
- PkcsUtils.cs
- WhitespaceRule.cs
- LinkedResourceCollection.cs
- CommandCollectionEditor.cs
- UriScheme.cs
- StreamingContext.cs
- WebZone.cs
- ProxyFragment.cs
- XmlSchemaSimpleTypeUnion.cs
- SspiNegotiationTokenProvider.cs
- EditingCommands.cs
- PartialTrustHelpers.cs
- ComPlusServiceHost.cs
- CodeSubDirectory.cs
- ToolStripLocationCancelEventArgs.cs
- MemoryRecordBuffer.cs
- FormsAuthenticationUserCollection.cs
- TdsEnums.cs
- ZoneButton.cs
- TextParaClient.cs
- HtmlEncodedRawTextWriter.cs
- ToolStripSplitStackLayout.cs
- PassportAuthentication.cs
- AppDomain.cs
- BatchWriter.cs
- XMLSyntaxException.cs
- WindowsGrip.cs
- FakeModelPropertyImpl.cs
- DeferredElementTreeState.cs
- UseLicense.cs
- AmbientLight.cs
- BamlLocalizableResource.cs
- FollowerQueueCreator.cs
- Point4DValueSerializer.cs
- HttpHeaderCollection.cs
- TextTabProperties.cs
- ObjectDataSourceMethodEventArgs.cs
- ErrorWebPart.cs
- OleStrCAMarshaler.cs
- ImageKeyConverter.cs
- MobilePage.cs
- UnsafeNativeMethods.cs
- DesignRelationCollection.cs
- DataBindingCollectionConverter.cs
- DesignerActionService.cs
- RegexRunnerFactory.cs
- FreezableDefaultValueFactory.cs
- _TransmitFileOverlappedAsyncResult.cs
- WebPartDisplayModeCollection.cs
- Pen.cs
- EdmToObjectNamespaceMap.cs
- DrawingContextWalker.cs
- InputProcessorProfiles.cs
- EvidenceTypeDescriptor.cs
- BindingCompleteEventArgs.cs
- ConfigsHelper.cs
- ConfigXmlCDataSection.cs
- ObfuscateAssemblyAttribute.cs
- DesignerSerializerAttribute.cs
- Vector3D.cs
- UpDownEvent.cs
- AssemblySettingAttributes.cs
- MsmqIntegrationProcessProtocolHandler.cs
- ProtectedUri.cs
- ScrollData.cs
- AuthorizationSection.cs
- XmlSchemaValidator.cs
- DoubleAnimation.cs
- StreamGeometry.cs
- SettingsPropertyCollection.cs
- HMACSHA512.cs
- SplashScreenNativeMethods.cs
- ReadOnlyNameValueCollection.cs
- ToolStripDropDownButton.cs
- ValidationHelper.cs
- GeneralTransformGroup.cs
- RuntimeResourceSet.cs
- HttpRawResponse.cs
- UnsafeCollabNativeMethods.cs
- SystemIPInterfaceProperties.cs
- StructuralCache.cs
- XamlBuildProvider.cs
- CounterCreationData.cs
- DiffuseMaterial.cs
- ObjectReferenceStack.cs
- WebBrowserSiteBase.cs
- SecurityImpersonationBehavior.cs
- RequestResizeEvent.cs
- Pens.cs
- ConfigurationSectionCollection.cs
- DrawingBrush.cs
- DesignerActionVerbItem.cs
- DynamicMethod.cs
- Query.cs
- TypedDatasetGenerator.cs
- ItemList.cs
- CollectionViewGroup.cs