Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- PaintValueEventArgs.cs
- KoreanLunisolarCalendar.cs
- JoinTreeNode.cs
- Rules.cs
- VarRefManager.cs
- ListViewGroup.cs
- Scalars.cs
- FilteredSchemaElementLookUpTable.cs
- AssemblyBuilderData.cs
- Themes.cs
- HttpCachePolicy.cs
- TemplatePropertyEntry.cs
- BitmapFrame.cs
- BinaryObjectReader.cs
- PassportPrincipal.cs
- CounterCreationDataCollection.cs
- NotificationContext.cs
- TablePattern.cs
- ProxyWebPartManager.cs
- TableRow.cs
- ReferentialConstraintRoleElement.cs
- DesigntimeLicenseContextSerializer.cs
- BitmapEffectGroup.cs
- arclist.cs
- WindowsTab.cs
- ProjectionPlan.cs
- QueryCacheEntry.cs
- ConfigXmlText.cs
- DataGridLinkButton.cs
- ScriptControlManager.cs
- WsdlParser.cs
- DSASignatureDeformatter.cs
- XPathPatternBuilder.cs
- SafeViewOfFileHandle.cs
- HMACRIPEMD160.cs
- ScrollViewer.cs
- EntityDataSourceEntityTypeFilterItem.cs
- VisualStyleTypesAndProperties.cs
- XmlStreamStore.cs
- DataGridViewCellConverter.cs
- DataControlCommands.cs
- TypeElement.cs
- GlyphRunDrawing.cs
- DataSourceIDConverter.cs
- DetailsViewPagerRow.cs
- PersonalizablePropertyEntry.cs
- WhereQueryOperator.cs
- MeasureItemEvent.cs
- Application.cs
- VerificationException.cs
- ResourcePermissionBase.cs
- XmlBoundElement.cs
- PinnedBufferMemoryStream.cs
- SuppressMessageAttribute.cs
- ConfigurationStrings.cs
- FixedDocumentSequencePaginator.cs
- FlowDocumentFormatter.cs
- SchemaCollectionCompiler.cs
- UntrustedRecipientException.cs
- ConsumerConnectionPoint.cs
- ModelService.cs
- ToolboxComponentsCreatedEventArgs.cs
- SortedList.cs
- _IPv4Address.cs
- Keywords.cs
- DetailsViewDeletedEventArgs.cs
- PenLineJoinValidation.cs
- SubpageParaClient.cs
- ToolboxSnapDragDropEventArgs.cs
- ExitEventArgs.cs
- ScriptControl.cs
- ProcessThread.cs
- DataBindEngine.cs
- DataSourceControlBuilder.cs
- EntityDataSourceDataSelectionPanel.designer.cs
- BindValidator.cs
- TriggerActionCollection.cs
- ResourceManager.cs
- EntityContainer.cs
- UpdateCommand.cs
- PeerTransportListenAddressValidatorAttribute.cs
- TextEditorParagraphs.cs
- HtmlElementErrorEventArgs.cs
- Pkcs9Attribute.cs
- Pointer.cs
- VectorKeyFrameCollection.cs
- ExpanderAutomationPeer.cs
- ClickablePoint.cs
- SimpleType.cs
- SecurityResources.cs
- CodeChecksumPragma.cs
- HScrollProperties.cs
- ApplicationContext.cs
- GridViewRowPresenterBase.cs
- SqlConnectionPoolProviderInfo.cs
- ToolStripInSituService.cs
- DocumentPage.cs
- GeneralTransform3D.cs
- TextRenderer.cs
- JsonClassDataContract.cs