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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ADMembershipUser.cs
- SamlAuthorizationDecisionStatement.cs
- GeneralTransform3D.cs
- VisualTreeUtils.cs
- ReadOnlyPermissionSet.cs
- TextFormatter.cs
- Compiler.cs
- Transactions.cs
- RangeValueProviderWrapper.cs
- XamlBrushSerializer.cs
- TrackingAnnotationCollection.cs
- PermissionAttributes.cs
- DateTimeHelper.cs
- CommonGetThemePartSize.cs
- ContextStaticAttribute.cs
- MarkupObject.cs
- SqlRemoveConstantOrderBy.cs
- ConfigsHelper.cs
- Stopwatch.cs
- SerializationFieldInfo.cs
- ColumnMapVisitor.cs
- Dump.cs
- OverflowException.cs
- XomlSerializationHelpers.cs
- Choices.cs
- CaseKeyBox.xaml.cs
- SafeHandle.cs
- RectKeyFrameCollection.cs
- OptimalTextSource.cs
- AdjustableArrowCap.cs
- GridViewColumn.cs
- TableHeaderCell.cs
- DataServiceProviderMethods.cs
- XpsSerializerWriter.cs
- SubstitutionList.cs
- Mouse.cs
- TreeNodeConverter.cs
- CryptoConfig.cs
- RangeValueProviderWrapper.cs
- SafeNativeMethods.cs
- ConfigurationFileMap.cs
- TextChange.cs
- ContourSegment.cs
- ParameterElement.cs
- GACMembershipCondition.cs
- SwitchLevelAttribute.cs
- KeyNameIdentifierClause.cs
- RuleConditionDialog.Designer.cs
- PhysicalOps.cs
- ProfileEventArgs.cs
- StorageTypeMapping.cs
- FunctionCommandText.cs
- OracleParameter.cs
- HtmlControlDesigner.cs
- SapiGrammar.cs
- __FastResourceComparer.cs
- lengthconverter.cs
- TableCellAutomationPeer.cs
- ProgressChangedEventArgs.cs
- ObjectCloneHelper.cs
- SqlProfileProvider.cs
- Nullable.cs
- RouteParameter.cs
- ObjectSet.cs
- TypeHelpers.cs
- TaiwanLunisolarCalendar.cs
- CompiledRegexRunner.cs
- CatalogPartChrome.cs
- UnicodeEncoding.cs
- AbstractDataSvcMapFileLoader.cs
- SqlFacetAttribute.cs
- Point4DValueSerializer.cs
- LoadRetryAsyncResult.cs
- Vector3DConverter.cs
- MulticastNotSupportedException.cs
- CompensationToken.cs
- ResourceExpressionBuilder.cs
- SpecialFolderEnumConverter.cs
- WmlPanelAdapter.cs
- FontWeight.cs
- DataGridCheckBoxColumn.cs
- ToolboxDataAttribute.cs
- IndividualDeviceConfig.cs
- QuaternionAnimation.cs
- Comparer.cs
- sqlcontext.cs
- SqlDataAdapter.cs
- TextElementEnumerator.cs
- WebPartCancelEventArgs.cs
- WeakReferenceEnumerator.cs
- webproxy.cs
- DesignerSerializerAttribute.cs
- CounterSample.cs
- ListViewGroupItemCollection.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- ResourceDescriptionAttribute.cs
- ContractMapping.cs
- DecodeHelper.cs
- ZipIOCentralDirectoryFileHeader.cs
- SQLBytesStorage.cs