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
- StandardBindingOptionalReliableSessionElement.cs
- ConsumerConnectionPointCollection.cs
- UInt64Converter.cs
- RightsManagementInformation.cs
- TreeViewCancelEvent.cs
- WindowsScrollBar.cs
- BooleanSwitch.cs
- XsdBuildProvider.cs
- GridViewSelectEventArgs.cs
- WebPartManager.cs
- PathFigure.cs
- NetSectionGroup.cs
- SerializationStore.cs
- UInt16Converter.cs
- Model3D.cs
- CorrelationRequestContext.cs
- DataGridViewCellConverter.cs
- LabelEditEvent.cs
- DecimalAnimationBase.cs
- NaturalLanguageHyphenator.cs
- XmlAttributeCollection.cs
- ControlTemplate.cs
- WindowsTreeView.cs
- Delay.cs
- ChtmlPageAdapter.cs
- HashHelper.cs
- BitmapEffectState.cs
- IteratorFilter.cs
- _ConnectStream.cs
- ProviderSettings.cs
- OpacityConverter.cs
- XamlStyleSerializer.cs
- Odbc32.cs
- HtmlTableCellCollection.cs
- CompilerState.cs
- RequestCachePolicy.cs
- IntSecurity.cs
- QueryContinueDragEventArgs.cs
- DynamicDataResources.Designer.cs
- ZipIORawDataFileBlock.cs
- SqlCommandSet.cs
- Content.cs
- ExceptionUtil.cs
- DeadCharTextComposition.cs
- BaseDataListPage.cs
- X500Name.cs
- AsymmetricSignatureDeformatter.cs
- LinkLabelLinkClickedEvent.cs
- DataGridTemplateColumn.cs
- CustomCredentialPolicy.cs
- Paragraph.cs
- XPathNodePointer.cs
- ClockGroup.cs
- SmtpMail.cs
- MSG.cs
- DoubleIndependentAnimationStorage.cs
- WaitHandleCannotBeOpenedException.cs
- BmpBitmapEncoder.cs
- DataGridColumnsPage.cs
- X509CertificateValidator.cs
- SharedDp.cs
- SessionSwitchEventArgs.cs
- EdmProperty.cs
- FrameworkTemplate.cs
- ProgressBarRenderer.cs
- TextElementEditingBehaviorAttribute.cs
- XmlWrappingReader.cs
- RuleProcessor.cs
- NameSpaceEvent.cs
- SurrogateSelector.cs
- SiteMembershipCondition.cs
- XmlSiteMapProvider.cs
- BitmapFrameEncode.cs
- ToolStripComboBox.cs
- OracleTransaction.cs
- SqlUnionizer.cs
- bidPrivateBase.cs
- PermissionListSet.cs
- ThreadSafeList.cs
- ThicknessAnimation.cs
- CalendarTable.cs
- ListViewItem.cs
- ListControl.cs
- PageContentCollection.cs
- DoubleConverter.cs
- HttpsChannelFactory.cs
- Span.cs
- MimeMapping.cs
- FixUp.cs
- BoundColumn.cs
- Int32Collection.cs
- DbModificationClause.cs
- ColorMap.cs
- WindowAutomationPeer.cs
- PanelDesigner.cs
- XmlFormatWriterGenerator.cs
- InvalidComObjectException.cs
- SelectionItemProviderWrapper.cs
- XmlQueryStaticData.cs
- TextTreeObjectNode.cs