Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlAtomicValue.cs
- CompilerGeneratedAttribute.cs
- CompositeActivityTypeDescriptorProvider.cs
- DataFieldEditor.cs
- IdnElement.cs
- Rule.cs
- TraceContextRecord.cs
- ResourceDefaultValueAttribute.cs
- InlineObject.cs
- IndexedString.cs
- SimpleWebHandlerParser.cs
- KerberosTicketHashIdentifierClause.cs
- EntityClientCacheKey.cs
- EndpointBehaviorElement.cs
- RemotingAttributes.cs
- Authorization.cs
- StrongNameUtility.cs
- GuidConverter.cs
- FigureParaClient.cs
- XMLUtil.cs
- CipherData.cs
- Message.cs
- JsonDeserializer.cs
- QueryCursorEventArgs.cs
- TextFormatterImp.cs
- DataGridViewCellCollection.cs
- MobileControlPersister.cs
- PropertyRecord.cs
- ApplicationSecurityManager.cs
- Propagator.ExtentPlaceholderCreator.cs
- IndexedEnumerable.cs
- DataColumnMappingCollection.cs
- Visual3DCollection.cs
- DefaultAssemblyResolver.cs
- IDictionary.cs
- TemplateControlBuildProvider.cs
- BinaryNode.cs
- Compress.cs
- FeatureSupport.cs
- ClientSideQueueItem.cs
- CancellationHandlerDesigner.cs
- ADConnectionHelper.cs
- FilterException.cs
- PartialCachingControl.cs
- FacetValueContainer.cs
- Rect3D.cs
- SQLInt16Storage.cs
- DBSchemaTable.cs
- XDRSchema.cs
- WsdlWriter.cs
- DecoderFallback.cs
- TabletCollection.cs
- ControlUtil.cs
- ObjectSet.cs
- Monitor.cs
- HitTestWithPointDrawingContextWalker.cs
- Process.cs
- HttpProfileBase.cs
- XLinq.cs
- SimplePropertyEntry.cs
- Int32Storage.cs
- SqlBuilder.cs
- SafeRegistryHandle.cs
- XmlIlVisitor.cs
- OdbcRowUpdatingEvent.cs
- Matrix3D.cs
- AudioFileOut.cs
- PopOutPanel.cs
- DesignerRegion.cs
- RecognizedPhrase.cs
- WizardStepBase.cs
- ZipPackage.cs
- CollectionChangeEventArgs.cs
- TrustManagerMoreInformation.cs
- ParseChildrenAsPropertiesAttribute.cs
- HttpResponse.cs
- ParamArrayAttribute.cs
- SchemaHelper.cs
- ReadWriteObjectLock.cs
- RangeValueProviderWrapper.cs
- DictionaryEntry.cs
- DesignerTransaction.cs
- RoutedEventHandlerInfo.cs
- ExcCanonicalXml.cs
- TaiwanCalendar.cs
- KnownBoxes.cs
- CellNormalizer.cs
- BuildResultCache.cs
- Logging.cs
- ErrorWrapper.cs
- ProcessRequestArgs.cs
- CodeMethodReturnStatement.cs
- KnownAssembliesSet.cs
- RotationValidation.cs
- HierarchicalDataBoundControl.cs
- AuthenticationModuleElementCollection.cs
- BuildResultCache.cs
- clipboard.cs
- Composition.cs
- COSERVERINFO.cs