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
- DataGridViewRowsAddedEventArgs.cs
- ItemsPanelTemplate.cs
- ISFClipboardData.cs
- ToolboxBitmapAttribute.cs
- TableItemPattern.cs
- Win32.cs
- DataGridTablesFactory.cs
- PropertyGridEditorPart.cs
- DateTimePicker.cs
- CheckBoxField.cs
- SoapSchemaMember.cs
- ShaderEffect.cs
- ByteViewer.cs
- CategoryNameCollection.cs
- FontFamilyConverter.cs
- UniqueEventHelper.cs
- PresentationSource.cs
- CollectionDataContractAttribute.cs
- Pkcs7Signer.cs
- altserialization.cs
- Set.cs
- FragmentQueryKB.cs
- Solver.cs
- Message.cs
- FlagsAttribute.cs
- Misc.cs
- TypeGenericEnumerableViewSchema.cs
- EmbeddedObject.cs
- FeatureSupport.cs
- EntityObject.cs
- XmlDocumentType.cs
- ACL.cs
- PagePropertiesChangingEventArgs.cs
- WebSysDefaultValueAttribute.cs
- VectorAnimation.cs
- DataGridViewControlCollection.cs
- DrawingGroup.cs
- cookiecontainer.cs
- CodeTypeDelegate.cs
- StorageSetMapping.cs
- EventRouteFactory.cs
- WrappedIUnknown.cs
- TCPListener.cs
- ValueQuery.cs
- URLString.cs
- ResourceExpressionBuilder.cs
- MetadataSerializer.cs
- SqlDataSourceConfigureFilterForm.cs
- OutArgumentConverter.cs
- ServiceContractViewControl.Designer.cs
- PropertyConverter.cs
- LoadedOrUnloadedOperation.cs
- Visual3D.cs
- DelimitedListTraceListener.cs
- TimeSpanOrInfiniteValidator.cs
- XmlWrappingReader.cs
- EtwTrace.cs
- TextStore.cs
- Int32RectValueSerializer.cs
- ExtensionQuery.cs
- ExpressionBuilderContext.cs
- Exception.cs
- TextFormatterHost.cs
- ClaimTypeRequirement.cs
- ExpressionConverter.cs
- CommandID.cs
- RawUIStateInputReport.cs
- OverrideMode.cs
- CallSiteHelpers.cs
- OperationParameterInfo.cs
- LinqDataSourceInsertEventArgs.cs
- SiteMapDataSource.cs
- IDispatchConstantAttribute.cs
- SelectionEditingBehavior.cs
- ProcessThread.cs
- XamlReader.cs
- WorkflowOperationContext.cs
- WhitespaceSignificantCollectionAttribute.cs
- TreeNodeStyle.cs
- ContainerUIElement3D.cs
- DataGridViewRowPostPaintEventArgs.cs
- ProxyWebPart.cs
- NameValueConfigurationCollection.cs
- GPPOINTF.cs
- ErrorProvider.cs
- TypeToken.cs
- DBCommandBuilder.cs
- FormView.cs
- ContextMenuStripActionList.cs
- DataTableClearEvent.cs
- StateInitialization.cs
- FileLogRecordHeader.cs
- HttpDebugHandler.cs
- ProbeDuplexAsyncResult.cs
- GeometryModel3D.cs
- AssociationProvider.cs
- ResourceExpression.cs
- DataColumn.cs
- Automation.cs
- ImageButton.cs