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
- XmlBindingWorker.cs
- FeatureManager.cs
- KeyValueSerializer.cs
- BufferAllocator.cs
- EnumMember.cs
- FormViewUpdatedEventArgs.cs
- AssemblyInfo.cs
- CollectionChangedEventManager.cs
- AnnotationComponentChooser.cs
- ProgramPublisher.cs
- ModifierKeysValueSerializer.cs
- PersistenceTypeAttribute.cs
- ClassGenerator.cs
- SchemaDeclBase.cs
- ScrollBar.cs
- AppDomainFactory.cs
- SettingsPropertyWrongTypeException.cs
- Request.cs
- DataGridAddNewRow.cs
- CodeDirectoryCompiler.cs
- NativeStructs.cs
- VirtualDirectoryMapping.cs
- WebPartEventArgs.cs
- PaintValueEventArgs.cs
- PropertyFilterAttribute.cs
- MetafileHeader.cs
- CodeDOMUtility.cs
- DataBoundControlHelper.cs
- ProcessThreadCollection.cs
- BamlBinaryWriter.cs
- StdValidatorsAndConverters.cs
- CodeFieldReferenceExpression.cs
- SelectionRange.cs
- InputDevice.cs
- MeasurementDCInfo.cs
- SizeKeyFrameCollection.cs
- WmlControlAdapter.cs
- PerformanceCounterManager.cs
- DataGridViewTopRowAccessibleObject.cs
- UpdatePanel.cs
- X509CertificateCollection.cs
- TemplateLookupAction.cs
- WinEventHandler.cs
- EntityDataSourceEntitySetNameItem.cs
- AssertFilter.cs
- FrameworkObject.cs
- _DynamicWinsockMethods.cs
- CalendarSelectionChangedEventArgs.cs
- RtfNavigator.cs
- KnownIds.cs
- DetailsViewDesigner.cs
- Image.cs
- ProjectionCamera.cs
- DependencyPropertyAttribute.cs
- CachingHintValidation.cs
- DropDownList.cs
- CuspData.cs
- RSAPKCS1KeyExchangeFormatter.cs
- DataBindingList.cs
- HashAlgorithm.cs
- GridErrorDlg.cs
- QilLiteral.cs
- DoubleUtil.cs
- SiteMapNodeCollection.cs
- EncoderFallback.cs
- SingleConverter.cs
- X500Name.cs
- SatelliteContractVersionAttribute.cs
- OleDbReferenceCollection.cs
- DataListItem.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- URLIdentityPermission.cs
- AsyncCompletedEventArgs.cs
- MergeFilterQuery.cs
- WeakReferenceKey.cs
- SecurityTraceRecordHelper.cs
- TextAutomationPeer.cs
- StorageRoot.cs
- FloatUtil.cs
- NameTable.cs
- ControlType.cs
- DataViewSettingCollection.cs
- HttpResponseInternalWrapper.cs
- SqlDependencyListener.cs
- SecurityUtils.cs
- connectionpool.cs
- StorageEntityTypeMapping.cs
- DynamicPropertyHolder.cs
- PropertyDescriptorGridEntry.cs
- InvalidDataException.cs
- SqlLiftWhereClauses.cs
- TdsEnums.cs
- GlyphCache.cs
- DataGridSortingEventArgs.cs
- SessionConnectionReader.cs
- MobileListItem.cs
- StackOverflowException.cs
- ScriptRegistrationManager.cs
- DigestTraceRecordHelper.cs
- ValidationEventArgs.cs