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
- HotSpotCollection.cs
- Journal.cs
- ConstrainedDataObject.cs
- RemotingServices.cs
- InputScopeManager.cs
- MediaTimeline.cs
- ImplicitInputBrush.cs
- TextBox.cs
- CheckBoxBaseAdapter.cs
- sqlpipe.cs
- SyndicationItem.cs
- CodeDelegateInvokeExpression.cs
- DbCommandTree.cs
- CodeTryCatchFinallyStatement.cs
- PackageStore.cs
- BasePattern.cs
- WebException.cs
- InternalConfigSettingsFactory.cs
- DiagnosticsConfiguration.cs
- LineInfo.cs
- KerberosReceiverSecurityToken.cs
- StreamFormatter.cs
- CodeNamespaceImport.cs
- XmlSchemaSimpleTypeRestriction.cs
- Trace.cs
- AsymmetricAlgorithm.cs
- Grammar.cs
- BindingsCollection.cs
- SmiXetterAccessMap.cs
- ProfileProvider.cs
- ObjectStorage.cs
- ContextQuery.cs
- ReadOnlyDataSource.cs
- DataGridViewAutoSizeModeEventArgs.cs
- ArrayHelper.cs
- SplineKeyFrames.cs
- SafeLocalMemHandle.cs
- SoapBinding.cs
- AuthorizationRuleCollection.cs
- RightNameExpirationInfoPair.cs
- CorePropertiesFilter.cs
- EditorZone.cs
- SqlClientWrapperSmiStreamChars.cs
- HtmlDocument.cs
- Encoder.cs
- TagPrefixAttribute.cs
- WindowsStartMenu.cs
- NullableIntSumAggregationOperator.cs
- UnicodeEncoding.cs
- AppDomainFactory.cs
- NestPullup.cs
- followingsibling.cs
- _NetworkingPerfCounters.cs
- DesignRelationCollection.cs
- Base64WriteStateInfo.cs
- MachineKeyConverter.cs
- BaseProcessor.cs
- _BasicClient.cs
- PageRequestManager.cs
- SafeArrayTypeMismatchException.cs
- GridViewCommandEventArgs.cs
- XLinq.cs
- LinqDataSourceUpdateEventArgs.cs
- CachingHintValidation.cs
- SrgsOneOf.cs
- HeaderElement.cs
- LabelExpression.cs
- Pair.cs
- TileBrush.cs
- CqlErrorHelper.cs
- DataRowExtensions.cs
- LabelLiteral.cs
- ScrollBarRenderer.cs
- RuntimeArgumentHandle.cs
- ScrollBarAutomationPeer.cs
- EdgeProfileValidation.cs
- HttpDebugHandler.cs
- TableLayoutPanel.cs
- HttpCachePolicy.cs
- UIElement3D.cs
- PropertyFilterAttribute.cs
- StaticTextPointer.cs
- XamlSerializationHelper.cs
- ConfigXmlAttribute.cs
- ZipPackage.cs
- ACL.cs
- HScrollBar.cs
- TransactionScope.cs
- DataBindingExpressionBuilder.cs
- DesignerWidgets.cs
- CodeEventReferenceExpression.cs
- WebServiceFault.cs
- ActivityTrace.cs
- AppLevelCompilationSectionCache.cs
- DataGridHelper.cs
- PrimarySelectionGlyph.cs
- SourceItem.cs
- ServiceDefaults.cs
- DiscoveryServerProtocol.cs
- InputLanguage.cs