Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / WeakReferenceKey.cs / 1305600 / 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
- NewItemsContextMenuStrip.cs
- PrivilegedConfigurationManager.cs
- EventsTab.cs
- JoinGraph.cs
- safex509handles.cs
- ComponentGlyph.cs
- BindMarkupExtensionSerializer.cs
- SplitContainer.cs
- DesignTimeVisibleAttribute.cs
- X509UI.cs
- SQLInt32.cs
- AssociationSetEnd.cs
- FormsAuthentication.cs
- AnyReturnReader.cs
- DbQueryCommandTree.cs
- WebPartRestoreVerb.cs
- Brushes.cs
- ClientSideQueueItem.cs
- Size3D.cs
- IOException.cs
- PropertyValueChangedEvent.cs
- CompiledQuery.cs
- UnsafeNativeMethods.cs
- EdgeModeValidation.cs
- CancelEventArgs.cs
- DodSequenceMerge.cs
- SyndicationCategory.cs
- ContentOperations.cs
- ConnectionPointCookie.cs
- ArraySegment.cs
- TriggerActionCollection.cs
- InheritanceAttribute.cs
- SQLRoleProvider.cs
- MissingMemberException.cs
- Internal.cs
- HttpResponse.cs
- SqlPersonalizationProvider.cs
- ManagementEventArgs.cs
- XamlTypeMapper.cs
- DataGridHyperlinkColumn.cs
- CompensatableTransactionScopeActivityDesigner.cs
- _LocalDataStore.cs
- StructuralObject.cs
- BStrWrapper.cs
- DataGridViewBindingCompleteEventArgs.cs
- CodeSnippetTypeMember.cs
- BitmapSizeOptions.cs
- DynamicDocumentPaginator.cs
- ValueCollectionParameterReader.cs
- ControlAdapter.cs
- mediaclock.cs
- ProcessRequestArgs.cs
- FilePrompt.cs
- DbDataSourceEnumerator.cs
- SecurityUtils.cs
- Point4D.cs
- HandlerBase.cs
- XmlSchemaInclude.cs
- TaiwanCalendar.cs
- ExpressionBindingCollection.cs
- SiteMapPathDesigner.cs
- DataSourceControlBuilder.cs
- UnsafeMethods.cs
- MetadataSource.cs
- IHttpResponseInternal.cs
- SessionState.cs
- MaskedTextBox.cs
- Dictionary.cs
- RC2CryptoServiceProvider.cs
- Base64Encoding.cs
- ComboBoxRenderer.cs
- MyContact.cs
- DiffuseMaterial.cs
- EndPoint.cs
- ArglessEventHandlerProxy.cs
- ChtmlImageAdapter.cs
- SequentialWorkflowHeaderFooter.cs
- ParameterElementCollection.cs
- CustomLineCap.cs
- TreeBuilderBamlTranslator.cs
- CodeAttributeDeclarationCollection.cs
- TextStore.cs
- DataAccessor.cs
- TextEditorParagraphs.cs
- SingletonInstanceContextProvider.cs
- Msec.cs
- PhonemeConverter.cs
- ChangeNode.cs
- RequestDescription.cs
- RouteValueExpressionBuilder.cs
- _OverlappedAsyncResult.cs
- SemaphoreSlim.cs
- SqlAggregateChecker.cs
- MimeMapping.cs
- ExtenderProvidedPropertyAttribute.cs
- DebugInfoGenerator.cs
- AssemblyHash.cs
- XmlSortKey.cs
- IntellisenseTextBox.designer.cs
- SymbolTable.cs