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
- RichTextBoxConstants.cs
- Authorization.cs
- ExtenderHelpers.cs
- XPathAxisIterator.cs
- ListViewDeletedEventArgs.cs
- IntSecurity.cs
- PixelShader.cs
- DecimalAnimationUsingKeyFrames.cs
- Compiler.cs
- Button.cs
- Schema.cs
- URLIdentityPermission.cs
- TextEndOfSegment.cs
- DataException.cs
- MonthCalendar.cs
- DataBinder.cs
- FormatterConverter.cs
- BindingSource.cs
- DataGridViewDataConnection.cs
- WebBrowserProgressChangedEventHandler.cs
- OdbcCommand.cs
- ActivationServices.cs
- MessageQueueConverter.cs
- userdatakeys.cs
- PenThreadWorker.cs
- WmfPlaceableFileHeader.cs
- SqlBuffer.cs
- TextBoxDesigner.cs
- FactoryGenerator.cs
- HostElement.cs
- LocalTransaction.cs
- PrinterUnitConvert.cs
- BatchServiceHost.cs
- SchemaName.cs
- StructuredTypeEmitter.cs
- SmtpNtlmAuthenticationModule.cs
- OAVariantLib.cs
- TextDecorationCollection.cs
- ProfessionalColorTable.cs
- AmbientValueAttribute.cs
- FilteredAttributeCollection.cs
- ContractUtils.cs
- ProcessHost.cs
- FormViewAutoFormat.cs
- KnownTypesHelper.cs
- SafeProcessHandle.cs
- NumberSubstitution.cs
- MutexSecurity.cs
- XmlRawWriter.cs
- CompilationSection.cs
- HttpListenerException.cs
- ColorMatrix.cs
- SerializationInfoEnumerator.cs
- JournalEntry.cs
- RowCache.cs
- Metadata.cs
- TreeNodeBindingDepthConverter.cs
- SamlSubject.cs
- MethodBuilder.cs
- ValidateNames.cs
- Oid.cs
- InternalControlCollection.cs
- DataObjectPastingEventArgs.cs
- BinaryMessageFormatter.cs
- SQLString.cs
- ExternalDataExchangeClient.cs
- EventMemberCodeDomSerializer.cs
- SwitchLevelAttribute.cs
- ExpressionLink.cs
- KeyValueSerializer.cs
- ComponentCodeDomSerializer.cs
- FontCollection.cs
- TextShapeableCharacters.cs
- CallbackTimeoutsBehavior.cs
- BamlLocalizer.cs
- FunctionMappingTranslator.cs
- StateMachineAction.cs
- MetadataWorkspace.cs
- DtcInterfaces.cs
- SkipQueryOptionExpression.cs
- ToolboxComponentsCreatedEventArgs.cs
- DataTableReader.cs
- Int32CollectionValueSerializer.cs
- MsmqChannelFactory.cs
- ColumnClickEvent.cs
- PngBitmapEncoder.cs
- IdentityModelDictionary.cs
- FamilyTypefaceCollection.cs
- SqlDataSourceDesigner.cs
- CalendarTable.cs
- TextAutomationPeer.cs
- XomlCompilerHelpers.cs
- XmlSchemaSimpleContentRestriction.cs
- DictionaryBase.cs
- ProjectionPruner.cs
- SerializationStore.cs
- XamlToRtfParser.cs
- BrushConverter.cs
- VirtualDirectoryMapping.cs
- DataGridCell.cs