Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- CommandBinding.cs
- VScrollBar.cs
- ReaderOutput.cs
- PeerTransportListenAddressConverter.cs
- ThreadStartException.cs
- ObjectKeyFrameCollection.cs
- OperationContractAttribute.cs
- MetaModel.cs
- isolationinterop.cs
- InvariantComparer.cs
- CodeLabeledStatement.cs
- FocusWithinProperty.cs
- SqlDataSourceSelectingEventArgs.cs
- PageEventArgs.cs
- EventRoute.cs
- FileDialogPermission.cs
- VisualStyleTypesAndProperties.cs
- CommandManager.cs
- RenameRuleObjectDialog.Designer.cs
- TableColumnCollection.cs
- documentsequencetextcontainer.cs
- TemplateField.cs
- FileCodeGroup.cs
- ConditionValidator.cs
- EmptyTextWriter.cs
- TextLineResult.cs
- TlsSspiNegotiation.cs
- WebPartConnectionsCloseVerb.cs
- ImageKeyConverter.cs
- PeerContact.cs
- Fault.cs
- CopyCodeAction.cs
- InfoCardKeyedHashAlgorithm.cs
- MyContact.cs
- WebPartZoneDesigner.cs
- XmlDownloadManager.cs
- tooltip.cs
- XmlWellformedWriter.cs
- DataPointer.cs
- Attribute.cs
- XmlStringTable.cs
- NullableDoubleSumAggregationOperator.cs
- DataRelationCollection.cs
- Instrumentation.cs
- PasswordDeriveBytes.cs
- TokenBasedSet.cs
- WebServiceBindingAttribute.cs
- SelectionItemProviderWrapper.cs
- DataGridViewTopRowAccessibleObject.cs
- PrivateFontCollection.cs
- HtmlTernaryTree.cs
- Vector.cs
- ModifierKeysConverter.cs
- Int16KeyFrameCollection.cs
- _UriSyntax.cs
- DupHandleConnectionReader.cs
- SoapFormatterSinks.cs
- VisualTransition.cs
- AnnotationHighlightLayer.cs
- RsaEndpointIdentity.cs
- BuildProviderCollection.cs
- SupportsEventValidationAttribute.cs
- Permission.cs
- MessageQueuePermissionEntryCollection.cs
- Menu.cs
- InternalSendMessage.cs
- XmlnsDefinitionAttribute.cs
- ListDesigner.cs
- TableLayoutPanel.cs
- MasterPageCodeDomTreeGenerator.cs
- FactoryMaker.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- ProviderMetadataCachedInformation.cs
- XpsFilter.cs
- StoreAnnotationsMap.cs
- DataSourceXmlElementAttribute.cs
- AsyncDataRequest.cs
- ArraySortHelper.cs
- UIElement3DAutomationPeer.cs
- ReservationCollection.cs
- TextPointerBase.cs
- PlatformNotSupportedException.cs
- ReadOnlyHierarchicalDataSourceView.cs
- MarshalByRefObject.cs
- AssemblyCache.cs
- FrameDimension.cs
- WebPartTransformer.cs
- CollectionBuilder.cs
- VersionPair.cs
- ApplicationException.cs
- cookiecollection.cs
- PagerStyle.cs
- PrinterResolution.cs
- X509Certificate.cs
- TargetFrameworkAttribute.cs
- RelatedCurrencyManager.cs
- ResourceAssociationSet.cs
- WebBrowsableAttribute.cs
- StringToken.cs
- TextSegment.cs