Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / MS / Internal / WeakReferenceKey.cs / 1 / 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
- EventRecord.cs
- ILGenerator.cs
- XpsPackagingException.cs
- NotificationContext.cs
- EntityCommandDefinition.cs
- EventSinkActivity.cs
- ReferencedAssembly.cs
- CompareInfo.cs
- Helper.cs
- FileSecurity.cs
- TileModeValidation.cs
- TextDecorationCollectionConverter.cs
- XmlChildEnumerator.cs
- RunClient.cs
- WebPartConnectionsCloseVerb.cs
- NameValuePermission.cs
- InputReferenceExpression.cs
- Deflater.cs
- ValueConversionAttribute.cs
- TextSelectionProcessor.cs
- DataSetUtil.cs
- TemplateApplicationHelper.cs
- DebugHandleTracker.cs
- RootBrowserWindow.cs
- DataGridHeaderBorder.cs
- SessionStateSection.cs
- HwndProxyElementProvider.cs
- FixedSOMLineRanges.cs
- LineUtil.cs
- RequestCache.cs
- ListViewItem.cs
- bindurihelper.cs
- WebChannelFactory.cs
- PartialToken.cs
- ReadOnlyCollection.cs
- DeclarativeCatalogPartDesigner.cs
- HandlerFactoryWrapper.cs
- WebPartEditVerb.cs
- RouteParameter.cs
- HttpServerVarsCollection.cs
- CharAnimationUsingKeyFrames.cs
- RectConverter.cs
- ProcessModuleCollection.cs
- OraclePermissionAttribute.cs
- DNS.cs
- LocalizableResourceBuilder.cs
- XmlNode.cs
- ActivityCompletionCallbackWrapper.cs
- CodeExporter.cs
- InvariantComparer.cs
- CqlGenerator.cs
- Crc32.cs
- CaseExpr.cs
- Utilities.cs
- SeekStoryboard.cs
- CreateUserWizard.cs
- DataGridCell.cs
- WebConfigurationHostFileChange.cs
- DocumentApplication.cs
- EntityDataSourceDesigner.cs
- MimeXmlReflector.cs
- HuffmanTree.cs
- ModelUtilities.cs
- DataGridViewAccessibleObject.cs
- TransportConfigurationTypeElementCollection.cs
- Profiler.cs
- RelatedEnd.cs
- ErrorRuntimeConfig.cs
- ColumnWidthChangingEvent.cs
- FixedSOMTextRun.cs
- DataGridAddNewRow.cs
- ConfigXmlAttribute.cs
- JsonServiceDocumentSerializer.cs
- CollectionDataContractAttribute.cs
- Root.cs
- PropertyGridDesigner.cs
- PhonemeEventArgs.cs
- HttpClientChannel.cs
- SecurityCriticalDataForSet.cs
- ComPlusContractBehavior.cs
- XmlSchemaSet.cs
- DataGridView.cs
- RegexCompilationInfo.cs
- UIElementIsland.cs
- ConstNode.cs
- AcceleratedTokenProviderState.cs
- ObjectDataSourceEventArgs.cs
- HashCryptoHandle.cs
- SendMailErrorEventArgs.cs
- Interop.cs
- TransformerInfo.cs
- RouteParameter.cs
- ParentUndoUnit.cs
- SafeRegistryHandle.cs
- HttpWrapper.cs
- QueryCacheEntry.cs
- ConfigXmlDocument.cs
- ActiveDocumentEvent.cs
- MD5.cs
- Base64Stream.cs