Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- ResourceDescriptionAttribute.cs
- UrlAuthorizationModule.cs
- QueryResultOp.cs
- LineVisual.cs
- CategoryNameCollection.cs
- CacheManager.cs
- Panel.cs
- DataGridLinkButton.cs
- DataBindingCollection.cs
- DSASignatureFormatter.cs
- TileBrush.cs
- AssociatedControlConverter.cs
- XmlDataSource.cs
- XamlClipboardData.cs
- AbsoluteQuery.cs
- NavigationProperty.cs
- Processor.cs
- ProgressiveCrcCalculatingStream.cs
- sqlnorm.cs
- TableCellAutomationPeer.cs
- IPCCacheManager.cs
- storepermissionattribute.cs
- SymmetricAlgorithm.cs
- WinEventHandler.cs
- ResXResourceReader.cs
- VectorAnimationUsingKeyFrames.cs
- SectionUpdates.cs
- HandlerWithFactory.cs
- DataMemberFieldConverter.cs
- TextPointerBase.cs
- SafeLibraryHandle.cs
- xml.cs
- WSFederationHttpBindingCollectionElement.cs
- RuntimeConfig.cs
- StringWriter.cs
- DbConnectionPoolGroup.cs
- PackageDocument.cs
- TextEditorTables.cs
- SID.cs
- SymbolUsageManager.cs
- DirectoryInfo.cs
- AnimatedTypeHelpers.cs
- CodeCommentStatementCollection.cs
- SqlServer2KCompatibilityCheck.cs
- NGCSerializerAsync.cs
- MetabaseSettingsIis7.cs
- XmlAttributes.cs
- SQLInt32.cs
- TextCollapsingProperties.cs
- TableLayoutSettingsTypeConverter.cs
- CurrentChangingEventArgs.cs
- DataGridViewCellEventArgs.cs
- SmiEventStream.cs
- ColumnClickEvent.cs
- BamlResourceSerializer.cs
- OperatingSystem.cs
- WindowsToolbarAsMenu.cs
- QuaternionKeyFrameCollection.cs
- ListBoxItem.cs
- ColorBuilder.cs
- CodeThrowExceptionStatement.cs
- ControlPaint.cs
- EventMappingSettingsCollection.cs
- FixedSchema.cs
- ItemsChangedEventArgs.cs
- DocumentGridContextMenu.cs
- DataGridViewDataErrorEventArgs.cs
- NetMsmqSecurity.cs
- PanelContainerDesigner.cs
- EventHandlersStore.cs
- ComponentRenameEvent.cs
- SiteIdentityPermission.cs
- TraceSwitch.cs
- DataGridViewLinkCell.cs
- OutputScope.cs
- ParserHooks.cs
- UserInitiatedNavigationPermission.cs
- BitmapEffectState.cs
- ListDictionaryInternal.cs
- SafeCoTaskMem.cs
- DeleteHelper.cs
- StylusButtonEventArgs.cs
- ProcessManager.cs
- UrlPropertyAttribute.cs
- SHA512Managed.cs
- ConstraintCollection.cs
- FigureHelper.cs
- _CommandStream.cs
- Memoizer.cs
- RoutedEventArgs.cs
- FunctionCommandText.cs
- TransactionFlowAttribute.cs
- DataServices.cs
- AtomContentProperty.cs
- ExistsInCollection.cs
- Propagator.cs
- DiscoveryClientChannelBase.cs
- NotifyParentPropertyAttribute.cs
- InProcStateClientManager.cs
- DBConcurrencyException.cs