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
- FontInfo.cs
- DataControlPagerLinkButton.cs
- Effect.cs
- XamlSerializerUtil.cs
- DesignConnectionCollection.cs
- RenderCapability.cs
- CompositeDataBoundControl.cs
- RectangleConverter.cs
- AutomationPatternInfo.cs
- LocalFileSettingsProvider.cs
- DateTimeValueSerializer.cs
- DataGridViewImageColumn.cs
- ProcessHost.cs
- InputLanguageCollection.cs
- FocusChangedEventArgs.cs
- ColumnMapCopier.cs
- TextMarkerSource.cs
- documentsequencetextcontainer.cs
- WebSysDisplayNameAttribute.cs
- Compiler.cs
- JsonReaderWriterFactory.cs
- Section.cs
- ResourceDescriptionAttribute.cs
- CustomAttributeSerializer.cs
- DictionaryTraceRecord.cs
- StrokeCollectionDefaultValueFactory.cs
- ServerType.cs
- DefaultTextStore.cs
- SignerInfo.cs
- WebControlAdapter.cs
- LinkedList.cs
- WebPartDescriptionCollection.cs
- SerializationInfoEnumerator.cs
- NativeMethods.cs
- ConfigurationFileMap.cs
- DynamicValueConverter.cs
- BindStream.cs
- CharEntityEncoderFallback.cs
- BuildProviderCollection.cs
- PrePrepareMethodAttribute.cs
- DynamicArgumentDesigner.xaml.cs
- UnionExpr.cs
- DataServiceRequestOfT.cs
- StructuralObject.cs
- TrackingServices.cs
- DataServiceQueryProvider.cs
- webproxy.cs
- RuleSetDialog.Designer.cs
- ReadOnlyHierarchicalDataSourceView.cs
- CommandArguments.cs
- BaseTemplateCodeDomTreeGenerator.cs
- SafeHandles.cs
- EntitySqlException.cs
- PathNode.cs
- XmlBindingWorker.cs
- ConnectionPoolManager.cs
- Utils.cs
- XmlArrayItemAttribute.cs
- IListConverters.cs
- ScrollChrome.cs
- SafeBuffer.cs
- CategoryNameCollection.cs
- DeferrableContentConverter.cs
- BroadcastEventHelper.cs
- RuleSetDialog.Designer.cs
- FixedSOMLineRanges.cs
- Material.cs
- ArraySubsetEnumerator.cs
- DetailsViewUpdateEventArgs.cs
- MachineKeySection.cs
- ProcessThreadCollection.cs
- RotateTransform3D.cs
- PlaceHolder.cs
- HeaderedContentControl.cs
- BufferBuilder.cs
- ScriptResourceAttribute.cs
- Rotation3D.cs
- MetadataItemEmitter.cs
- HtmlInputControl.cs
- __TransparentProxy.cs
- InterleavedZipPartStream.cs
- CodeMemberProperty.cs
- Propagator.JoinPropagator.cs
- Model3DGroup.cs
- GeometryDrawing.cs
- TypeDelegator.cs
- ConnectionStringSettings.cs
- ReverseInheritProperty.cs
- FixedSOMContainer.cs
- _LoggingObject.cs
- LowerCaseStringConverter.cs
- StronglyTypedResourceBuilder.cs
- compensatingcollection.cs
- XmlMembersMapping.cs
- HighlightComponent.cs
- ControlIdConverter.cs
- StoreContentChangedEventArgs.cs
- CopyNodeSetAction.cs
- LineServicesCallbacks.cs
- SemanticKeyElement.cs