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
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BinarySecretSecurityToken.cs
- Renderer.cs
- Codec.cs
- EntityConnection.cs
- RTLAwareMessageBox.cs
- DataContractSet.cs
- WebBrowserPermission.cs
- TrackingConditionCollection.cs
- XmlBindingWorker.cs
- altserialization.cs
- Pen.cs
- Rfc2898DeriveBytes.cs
- Pair.cs
- ThemeInfoAttribute.cs
- SiteMapNodeItemEventArgs.cs
- OleDbParameter.cs
- TextContainer.cs
- EventMappingSettings.cs
- X500Name.cs
- ProcessHostFactoryHelper.cs
- _NtlmClient.cs
- XmlDataLoader.cs
- DataGridViewColumn.cs
- XsdDuration.cs
- EngineSite.cs
- CustomError.cs
- LambdaCompiler.Address.cs
- CharEnumerator.cs
- EventLogLink.cs
- ImplicitInputBrush.cs
- HtmlElementEventArgs.cs
- EntitySetBase.cs
- ComponentDispatcherThread.cs
- XmlQueryStaticData.cs
- Container.cs
- _SSPIWrapper.cs
- BamlRecordReader.cs
- SecureUICommand.cs
- entityreference_tresulttype.cs
- FileLoadException.cs
- WindowsStatic.cs
- SqlCrossApplyToCrossJoin.cs
- ColorPalette.cs
- MouseGestureValueSerializer.cs
- CorrelationQuery.cs
- OleDbReferenceCollection.cs
- UnsafeNativeMethods.cs
- Condition.cs
- ProcessThread.cs
- OracleCommandBuilder.cs
- WorkflowDefinitionDispenser.cs
- XmlC14NWriter.cs
- EnlistmentTraceIdentifier.cs
- StringFreezingAttribute.cs
- WebHttpElement.cs
- SecurityDescriptor.cs
- IsolatedStorageFileStream.cs
- ToolStripDropDownClosedEventArgs.cs
- CardSpaceException.cs
- MenuBase.cs
- WebRequest.cs
- WriteableBitmap.cs
- MailHeaderInfo.cs
- WinInet.cs
- DataBoundLiteralControl.cs
- SmiRecordBuffer.cs
- Matrix3DStack.cs
- documentsequencetextpointer.cs
- WinEventHandler.cs
- WebPartDisplayModeCollection.cs
- WsatConfiguration.cs
- HostnameComparisonMode.cs
- UnicastIPAddressInformationCollection.cs
- CompositeDataBoundControl.cs
- OleCmdHelper.cs
- SimpleFieldTemplateUserControl.cs
- ClientProxyGenerator.cs
- FlowLayout.cs
- PageRequestManager.cs
- CreationContext.cs
- Size.cs
- ExtenderProvidedPropertyAttribute.cs
- CaseStatement.cs
- SettingsProviderCollection.cs
- RoutedEventArgs.cs
- TileModeValidation.cs
- Splitter.cs
- ListBoxItemWrapperAutomationPeer.cs
- QilLiteral.cs
- ObjectSecurity.cs
- ListControlConvertEventArgs.cs
- ProfileProvider.cs
- TaskFileService.cs
- Logging.cs
- MetadataArtifactLoaderCompositeResource.cs
- Wrapper.cs
- XamlPointCollectionSerializer.cs
- ResourceDefaultValueAttribute.cs
- ExitEventArgs.cs
- CodeTypeDelegate.cs