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
- SafeThemeHandle.cs
- Storyboard.cs
- HashStream.cs
- KerberosTokenFactoryCredential.cs
- AuthenticatedStream.cs
- XmlQueryStaticData.cs
- RegexParser.cs
- ListViewItemSelectionChangedEvent.cs
- ISAPIRuntime.cs
- RenderDataDrawingContext.cs
- DBNull.cs
- ByteConverter.cs
- WindowsAuthenticationModule.cs
- ApplicationDirectoryMembershipCondition.cs
- CompensateDesigner.cs
- ActiveXHost.cs
- FormsAuthenticationCredentials.cs
- Constants.cs
- DebugView.cs
- DetailsViewInsertedEventArgs.cs
- LostFocusEventManager.cs
- AttributeQuery.cs
- CompilerErrorCollection.cs
- ItemPager.cs
- TypeHelper.cs
- HwndStylusInputProvider.cs
- TypeDescriptorContext.cs
- PostBackOptions.cs
- ListViewGroupItemCollection.cs
- TracePayload.cs
- Size.cs
- ImportCatalogPart.cs
- TypeDependencyAttribute.cs
- PageThemeParser.cs
- QueryExpression.cs
- UserControlFileEditor.cs
- PeerFlooder.cs
- VirtualPathUtility.cs
- ResourceContainerWrapper.cs
- HashAlgorithm.cs
- LogAppendAsyncResult.cs
- SqlDelegatedTransaction.cs
- HelpProvider.cs
- DiscoveryClient.cs
- ApplicationDirectoryMembershipCondition.cs
- OleDbPropertySetGuid.cs
- ScrollPatternIdentifiers.cs
- ContextProperty.cs
- HttpListenerRequest.cs
- CalendarDateRangeChangingEventArgs.cs
- WebConfigurationManager.cs
- ObjectDisposedException.cs
- LineGeometry.cs
- ConfigXmlCDataSection.cs
- _Semaphore.cs
- Site.cs
- HtmlElementEventArgs.cs
- SmtpException.cs
- BaseParser.cs
- SelectorItemAutomationPeer.cs
- SettingsAttributes.cs
- SecureEnvironment.cs
- HMACSHA1.cs
- ForeignKeyConstraint.cs
- DataTrigger.cs
- ExpandCollapseProviderWrapper.cs
- ProxyManager.cs
- DoubleAnimation.cs
- EpmCustomContentDeSerializer.cs
- HttpPostedFile.cs
- Camera.cs
- PeerCustomResolverElement.cs
- TextViewDesigner.cs
- EntityCodeGenerator.cs
- CustomError.cs
- SafeNativeMethods.cs
- InputScopeConverter.cs
- XPathItem.cs
- TypeTypeConverter.cs
- WmpBitmapEncoder.cs
- sqlmetadatafactory.cs
- Int32AnimationUsingKeyFrames.cs
- QilGenerator.cs
- DBCSCodePageEncoding.cs
- SoapProtocolImporter.cs
- OracleParameterBinding.cs
- TextTreeText.cs
- GridViewColumnCollectionChangedEventArgs.cs
- SourceItem.cs
- RangeValuePattern.cs
- TimeIntervalCollection.cs
- HwndAppCommandInputProvider.cs
- EnglishPluralizationService.cs
- SafeHandles.cs
- CodeSpit.cs
- GeneralTransform3DCollection.cs
- DataRowCollection.cs
- ObfuscationAttribute.cs
- ServiceContractGenerationContext.cs
- TagPrefixAttribute.cs