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
- Matrix3D.cs
- WindowsSecurityToken.cs
- CompileLiteralTextParser.cs
- ContentPresenter.cs
- TemplateDefinition.cs
- QuadTree.cs
- OleDbWrapper.cs
- EncoderBestFitFallback.cs
- SystemIcmpV4Statistics.cs
- EventMappingSettingsCollection.cs
- RestHandler.cs
- AssociatedControlConverter.cs
- XPathPatternBuilder.cs
- LocatorGroup.cs
- WebServiceEnumData.cs
- UIPermission.cs
- TdsRecordBufferSetter.cs
- InvariantComparer.cs
- EntityContainerRelationshipSetEnd.cs
- AppDomainManager.cs
- TrackingMemoryStream.cs
- WindowsMenu.cs
- RtfFormatStack.cs
- NullRuntimeConfig.cs
- SamlAudienceRestrictionCondition.cs
- XmlNodeList.cs
- Point3DKeyFrameCollection.cs
- Int32Rect.cs
- GridViewRowEventArgs.cs
- SessionStateItemCollection.cs
- SqlFormatter.cs
- ToolStripItemCollection.cs
- Parallel.cs
- OutputBuffer.cs
- TimeStampChecker.cs
- RichTextBox.cs
- XmlIlVisitor.cs
- dataprotectionpermission.cs
- PlatformNotSupportedException.cs
- DrawingServices.cs
- ListChangedEventArgs.cs
- DrawListViewSubItemEventArgs.cs
- WebServiceErrorEvent.cs
- Substitution.cs
- DebuggerAttributes.cs
- EllipseGeometry.cs
- Propagator.Evaluator.cs
- DetailsView.cs
- ParenExpr.cs
- AudioBase.cs
- TextOutput.cs
- FontEmbeddingManager.cs
- EarlyBoundInfo.cs
- MissingMemberException.cs
- IndexedEnumerable.cs
- OdbcCommandBuilder.cs
- AdornedElementPlaceholder.cs
- EventLogPermissionEntryCollection.cs
- UpdateCommand.cs
- Char.cs
- GradientSpreadMethodValidation.cs
- HMACMD5.cs
- BitVector32.cs
- RegexCapture.cs
- RegistryPermission.cs
- ScriptBehaviorDescriptor.cs
- SingleSelectRootGridEntry.cs
- CompositeDuplexElement.cs
- TextDecorationCollection.cs
- MiniMapControl.xaml.cs
- TrustLevelCollection.cs
- ReliableChannelBinder.cs
- MetadataCollection.cs
- ForEachAction.cs
- XslVisitor.cs
- Matrix3DStack.cs
- ClrPerspective.cs
- ClosureBinding.cs
- DateTimeUtil.cs
- __TransparentProxy.cs
- LogExtentCollection.cs
- DigitalSignature.cs
- XAMLParseException.cs
- PeerInvitationResponse.cs
- MutableAssemblyCacheEntry.cs
- QilInvokeLateBound.cs
- Pen.cs
- Baml2006KnownTypes.cs
- MissingManifestResourceException.cs
- UserThread.cs
- SafeNativeMethods.cs
- ItemCheckEvent.cs
- Tuple.cs
- wgx_render.cs
- TreeViewImageKeyConverter.cs
- AttachInfo.cs
- TokenBasedSetEnumerator.cs
- XdrBuilder.cs
- DescendantQuery.cs
- _ServiceNameStore.cs