Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- MetaTable.cs
- TabItemWrapperAutomationPeer.cs
- PeerCollaborationPermission.cs
- ComplexTypeEmitter.cs
- Int16Animation.cs
- UnitySerializationHolder.cs
- VisualStyleElement.cs
- ValidationHelpers.cs
- XmlDataImplementation.cs
- EntityDataSourceContextCreatingEventArgs.cs
- ViewBox.cs
- ListItemParagraph.cs
- InvalidFilterCriteriaException.cs
- WebPartManagerInternals.cs
- RenderingEventArgs.cs
- PropertyMappingExceptionEventArgs.cs
- ReferenceEqualityComparer.cs
- LineSegment.cs
- unitconverter.cs
- LifetimeMonitor.cs
- BuildResultCache.cs
- InputBinding.cs
- CatalogPartChrome.cs
- hresults.cs
- Rect3DValueSerializer.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- EnterpriseServicesHelper.cs
- QueryGeneratorBase.cs
- KeyInterop.cs
- ZipIOLocalFileHeader.cs
- ListChangedEventArgs.cs
- CompensatableTransactionScopeActivity.cs
- TextBoxAutomationPeer.cs
- ServiceActivationException.cs
- PanelContainerDesigner.cs
- InboundActivityHelper.cs
- ZipQueryOperator.cs
- _CookieModule.cs
- Compiler.cs
- ExtenderHelpers.cs
- DiscoveryDocument.cs
- CodeIdentifiers.cs
- nulltextcontainer.cs
- StringUtil.cs
- InputLangChangeRequestEvent.cs
- ProcessInputEventArgs.cs
- SendMailErrorEventArgs.cs
- MembershipAdapter.cs
- ColorConvertedBitmapExtension.cs
- DLinqDataModelProvider.cs
- DesignTimeXamlWriter.cs
- ListViewContainer.cs
- PathParser.cs
- OracleParameterBinding.cs
- SQLDouble.cs
- AnnotationService.cs
- _PooledStream.cs
- MessageUtil.cs
- PropertyInformationCollection.cs
- DisplayNameAttribute.cs
- TextOptions.cs
- DataGridRowEventArgs.cs
- XmlnsCompatibleWithAttribute.cs
- XmlSchema.cs
- SupportsEventValidationAttribute.cs
- ContextDataSourceContextData.cs
- GenericWebPart.cs
- StreamGeometry.cs
- LocationEnvironment.cs
- FormsIdentity.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- Delegate.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- SqlDataRecord.cs
- PeerName.cs
- EventSourceCreationData.cs
- ValidationEventArgs.cs
- BamlTreeNode.cs
- SecurityKeyEntropyMode.cs
- ELinqQueryState.cs
- DataControlFieldCell.cs
- WorkBatch.cs
- ViewStateException.cs
- WinFormsSpinner.cs
- indexingfiltermarshaler.cs
- SemanticKeyElement.cs
- MethodMessage.cs
- DropShadowBitmapEffect.cs
- CodeAttributeDeclarationCollection.cs
- CommonXSendMessage.cs
- DoubleLinkListEnumerator.cs
- URLString.cs
- PropertyEmitterBase.cs
- CSharpCodeProvider.cs
- WindowAutomationPeer.cs
- unsafenativemethodstextservices.cs
- ListParaClient.cs
- Guid.cs
- TextTreeRootTextBlock.cs
- PersonalizableAttribute.cs