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
- ManagementEventWatcher.cs
- AnimationLayer.cs
- DocumentViewerConstants.cs
- CopyCodeAction.cs
- StringCollectionEditor.cs
- AnimationStorage.cs
- InputElement.cs
- UrlMappingsSection.cs
- DnsPermission.cs
- DataRecordObjectView.cs
- DataGridViewCellStyleConverter.cs
- GeneralTransform3D.cs
- HttpProfileGroupBase.cs
- RoutedEventConverter.cs
- BinaryMessageFormatter.cs
- DataRecord.cs
- IndentedTextWriter.cs
- SortKey.cs
- UInt64Converter.cs
- ObjectQuery.cs
- SoapHeaderAttribute.cs
- PreloadedPackages.cs
- Image.cs
- PairComparer.cs
- HelloMessageCD1.cs
- WindowsStatusBar.cs
- HwndMouseInputProvider.cs
- ResourceReader.cs
- EnumMember.cs
- EmptyTextWriter.cs
- CatalogZoneBase.cs
- DefaultBinder.cs
- PageThemeParser.cs
- SubstitutionList.cs
- XmlWriterDelegator.cs
- OleDbInfoMessageEvent.cs
- WeakReferenceList.cs
- Component.cs
- CoordinationService.cs
- WebPartZone.cs
- Header.cs
- HostedImpersonationContext.cs
- Vertex.cs
- GenericWebPart.cs
- ConsumerConnectionPoint.cs
- PolicyLevel.cs
- CdpEqualityComparer.cs
- AnimationClock.cs
- SBCSCodePageEncoding.cs
- Ray3DHitTestResult.cs
- DBAsyncResult.cs
- Transactions.cs
- ProtocolsConfigurationEntry.cs
- EventWaitHandle.cs
- _MultipleConnectAsync.cs
- TreeViewDesigner.cs
- ArcSegment.cs
- NavigationPropertyEmitter.cs
- TextElement.cs
- CopyNamespacesAction.cs
- ConfigurationException.cs
- _BasicClient.cs
- XsltSettings.cs
- XPathEmptyIterator.cs
- RegexBoyerMoore.cs
- HtmlInputSubmit.cs
- UshortList2.cs
- InvalidChannelBindingException.cs
- InternalControlCollection.cs
- PersonalizationProvider.cs
- cookieexception.cs
- SqlXmlStorage.cs
- DurableRuntimeValidator.cs
- WindowsIdentity.cs
- ServiceDescriptionReflector.cs
- MobileUITypeEditor.cs
- Matrix.cs
- SystemSounds.cs
- CFGGrammar.cs
- SimpleHandlerFactory.cs
- XmlSchemaExporter.cs
- UrlPath.cs
- HostingEnvironmentSection.cs
- CheckBoxPopupAdapter.cs
- FactoryGenerator.cs
- BooleanStorage.cs
- SessionSwitchEventArgs.cs
- IncrementalReadDecoders.cs
- ProxyOperationRuntime.cs
- XsdDateTime.cs
- ToolStripScrollButton.cs
- ValidatedControlConverter.cs
- ShapingWorkspace.cs
- EventData.cs
- SamlAssertion.cs
- SemaphoreFullException.cs
- MetadataArtifactLoaderResource.cs
- EmptyEnumerator.cs
- LinqDataSourceDeleteEventArgs.cs
- SqlDependency.cs