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
- List.cs
- AliasExpr.cs
- ElementProxy.cs
- ColumnHeader.cs
- SqlPersonalizationProvider.cs
- ActiveDocumentEvent.cs
- MsmqAuthenticationMode.cs
- Tool.cs
- MouseActionValueSerializer.cs
- FreezableDefaultValueFactory.cs
- ToolStripDropDown.cs
- PenCursorManager.cs
- TableCellAutomationPeer.cs
- Matrix3DConverter.cs
- Thread.cs
- RectAnimationBase.cs
- QuotedStringWriteStateInfo.cs
- MoveSizeWinEventHandler.cs
- AttachedPropertyMethodSelector.cs
- PagesSection.cs
- GridViewDeleteEventArgs.cs
- DataObjectAttribute.cs
- TablePatternIdentifiers.cs
- LinearKeyFrames.cs
- TableParaClient.cs
- ClaimTypeElement.cs
- TextPointer.cs
- OptimalBreakSession.cs
- SymbolType.cs
- XmlSchemaImporter.cs
- InternalCompensate.cs
- OleDbMetaDataFactory.cs
- FunctionParameter.cs
- ConfigXmlElement.cs
- ComponentEvent.cs
- DispatchWrapper.cs
- DocumentViewer.cs
- CapabilitiesSection.cs
- TriState.cs
- SimpleLine.cs
- QueryStringConverter.cs
- MarginsConverter.cs
- JournalEntry.cs
- WebZoneDesigner.cs
- LinqDataSourceView.cs
- RadialGradientBrush.cs
- SelectionRangeConverter.cs
- ListViewGroup.cs
- SystemIPGlobalStatistics.cs
- ViewKeyConstraint.cs
- Odbc32.cs
- BufferedReadStream.cs
- ListBindingHelper.cs
- PreProcessInputEventArgs.cs
- InfoCardRequestException.cs
- ContainerParaClient.cs
- BulletedListEventArgs.cs
- PointLightBase.cs
- PartialCachingControl.cs
- RepeaterItemCollection.cs
- GuidConverter.cs
- BitmapEffect.cs
- SqlTopReducer.cs
- PriorityBindingExpression.cs
- CodeMethodInvokeExpression.cs
- BigIntegerStorage.cs
- LineGeometry.cs
- ConfigurationValidatorAttribute.cs
- ColorAnimation.cs
- Speller.cs
- GrammarBuilderDictation.cs
- SoapException.cs
- _Connection.cs
- FixedTextContainer.cs
- COAUTHINFO.cs
- Bidi.cs
- CodeDefaultValueExpression.cs
- DataRelationPropertyDescriptor.cs
- XmlParserContext.cs
- CommonProperties.cs
- EditorZoneAutoFormat.cs
- EntityDataSourceSelectingEventArgs.cs
- ComponentResourceManager.cs
- MdiWindowListItemConverter.cs
- OracleInternalConnection.cs
- ElementMarkupObject.cs
- RefreshPropertiesAttribute.cs
- Matrix.cs
- TracedNativeMethods.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- TreeView.cs
- UIAgentRequest.cs
- ChildTable.cs
- Brush.cs
- ErrorLog.cs
- InheritanceContextHelper.cs
- TCPClient.cs
- XsdCachingReader.cs
- ErasingStroke.cs
- SEHException.cs