Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Base / MS / Internal / BaseHashHelper.cs / 1 / BaseHashHelper.cs
//---------------------------------------------------------------------------- // //// Copyright (C) 2003 by Microsoft Corporation. All rights reserved. // // // // Description: Static class to help work around hashing-related bugs. // //--------------------------------------------------------------------------- using System; using System.Reflection; // Assembly using System.Collections.Specialized; // HybridDictionary using MS.Internal.WindowsBase; // [FriendAccessAllowed] namespace MS.Internal { [FriendAccessAllowed] // defined in Base, used in Core and Framework internal static class BaseHashHelper { static BaseHashHelper() { // register bad types from WindowsBase MS.Internal.Hashing.WindowsBase.HashHelper.Initialize(); } [FriendAccessAllowed] // defined in Base, used in Core and Framework internal static void RegisterTypes(Assembly assembly, Type[] types) { HybridDictionary dictionary = DictionaryFromList(types); lock(_table) { _table[assembly] = dictionary; } } // Some types don't have reliable hash codes - the hashcode can change // during the lifetime of an object of that type. Such an object cannot // be used as the key of a hashtable or dictionary. This is where we // detect such objects, so the caller can find some other way to cope. [FriendAccessAllowed] // defined in Base, used in Core and Framework internal static bool HasReliableHashCode(object item) { // null doesn't actually have a hashcode at all. This method can be // called with a representative item from a collection - if the // representative is null, we'll be pessimistic and assume the // items in the collection should not be hashed. if (item == null) return false; Type type = item.GetType(); Assembly assembly = type.Assembly; HybridDictionary dictionary; lock(_table) { dictionary = (HybridDictionary)_table[assembly]; } if (dictionary == null) { // if we don't have an entry for the object's assembly, // see if we know something about the assembly /* no external types on the `blacklist any more if (type.Namespace == "System.Data" && IsSystemData(assembly)) { dictionary = TypesForSystemData(); } else */ { // if we don't know anything about the assembly, give it an // empty dictionary. This makes future lookups fast. We just // have to hope that every type in the assembly has reliable // hashcodes. dictionary = new HybridDictionary(); } lock(_table) { _table[assembly] = dictionary; } } return !dictionary.Contains(type); } // populate a dictionary from the given list private static HybridDictionary DictionaryFromList(Type[] types) { HybridDictionary dictionary = new HybridDictionary(types.Length); for (int i=0; i// Copyright (C) 2003 by Microsoft Corporation. All rights reserved. // // // // Description: Static class to help work around hashing-related bugs. // //--------------------------------------------------------------------------- using System; using System.Reflection; // Assembly using System.Collections.Specialized; // HybridDictionary using MS.Internal.WindowsBase; // [FriendAccessAllowed] namespace MS.Internal { [FriendAccessAllowed] // defined in Base, used in Core and Framework internal static class BaseHashHelper { static BaseHashHelper() { // register bad types from WindowsBase MS.Internal.Hashing.WindowsBase.HashHelper.Initialize(); } [FriendAccessAllowed] // defined in Base, used in Core and Framework internal static void RegisterTypes(Assembly assembly, Type[] types) { HybridDictionary dictionary = DictionaryFromList(types); lock(_table) { _table[assembly] = dictionary; } } // Some types don't have reliable hash codes - the hashcode can change // during the lifetime of an object of that type. Such an object cannot // be used as the key of a hashtable or dictionary. This is where we // detect such objects, so the caller can find some other way to cope. [FriendAccessAllowed] // defined in Base, used in Core and Framework internal static bool HasReliableHashCode(object item) { // null doesn't actually have a hashcode at all. This method can be // called with a representative item from a collection - if the // representative is null, we'll be pessimistic and assume the // items in the collection should not be hashed. if (item == null) return false; Type type = item.GetType(); Assembly assembly = type.Assembly; HybridDictionary dictionary; lock(_table) { dictionary = (HybridDictionary)_table[assembly]; } if (dictionary == null) { // if we don't have an entry for the object's assembly, // see if we know something about the assembly /* no external types on the `blacklist any more if (type.Namespace == "System.Data" && IsSystemData(assembly)) { dictionary = TypesForSystemData(); } else */ { // if we don't know anything about the assembly, give it an // empty dictionary. This makes future lookups fast. We just // have to hope that every type in the assembly has reliable // hashcodes. dictionary = new HybridDictionary(); } lock(_table) { _table[assembly] = dictionary; } } return !dictionary.Contains(type); } // populate a dictionary from the given list private static HybridDictionary DictionaryFromList(Type[] types) { HybridDictionary dictionary = new HybridDictionary(types.Length); for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CollectionViewGroup.cs
- TemplateBindingExpressionConverter.cs
- CaseInsensitiveHashCodeProvider.cs
- DataControlFieldHeaderCell.cs
- TreeNodeCollection.cs
- UnwrappedTypesXmlSerializerManager.cs
- FormatVersion.cs
- FactoryGenerator.cs
- AssemblyAttributesGoHere.cs
- ButtonField.cs
- PartialTrustVisibleAssembly.cs
- AutoCompleteStringCollection.cs
- PermissionListSet.cs
- ClaimComparer.cs
- SoapMessage.cs
- HitTestWithPointDrawingContextWalker.cs
- ProfessionalColors.cs
- DataBoundControlAdapter.cs
- AnimationStorage.cs
- MultiSelector.cs
- _TimerThread.cs
- ClientTarget.cs
- SerialErrors.cs
- Setter.cs
- CodeAccessSecurityEngine.cs
- SingleAnimationBase.cs
- CssStyleCollection.cs
- RubberbandSelector.cs
- RealizationDrawingContextWalker.cs
- CultureTable.cs
- TabletDeviceInfo.cs
- SqlParameterCollection.cs
- MimeMapping.cs
- CssClassPropertyAttribute.cs
- List.cs
- CopyAttributesAction.cs
- ListView.cs
- QuotedPrintableStream.cs
- WindowInteractionStateTracker.cs
- CompiledQueryCacheEntry.cs
- MimeMapping.cs
- LineMetrics.cs
- Propagator.cs
- ReadWriteSpinLock.cs
- StringDictionary.cs
- ChildrenQuery.cs
- GacUtil.cs
- Vector3DKeyFrameCollection.cs
- LZCodec.cs
- AssemblyContextControlItem.cs
- DummyDataSource.cs
- LinkClickEvent.cs
- OutputScope.cs
- DES.cs
- MatrixConverter.cs
- ButtonFlatAdapter.cs
- ToolboxDataAttribute.cs
- CollectionChangedEventManager.cs
- FontFamily.cs
- Compiler.cs
- StateChangeEvent.cs
- SQLDecimal.cs
- VersionPair.cs
- BamlLocalizableResource.cs
- Enum.cs
- ScrollBarAutomationPeer.cs
- DeflateEmulationStream.cs
- SystemResourceKey.cs
- LineGeometry.cs
- IdleTimeoutMonitor.cs
- CssStyleCollection.cs
- SessionEndingCancelEventArgs.cs
- InitializationEventAttribute.cs
- JpegBitmapDecoder.cs
- compensatingcollection.cs
- StandardCommandToolStripMenuItem.cs
- XPathPatternParser.cs
- mediapermission.cs
- TileBrush.cs
- BitmapMetadataBlob.cs
- ChannelProtectionRequirements.cs
- BuildManager.cs
- DrawToolTipEventArgs.cs
- DescendantQuery.cs
- XmlExceptionHelper.cs
- OleDbConnection.cs
- StyleSelector.cs
- SafeViewOfFileHandle.cs
- ColumnMapTranslator.cs
- PersonalizationState.cs
- PtsPage.cs
- DataRecordInfo.cs
- CommandID.cs
- HostSecurityManager.cs
- MobileUserControlDesigner.cs
- TextDecorationCollection.cs
- ServiceModelPerformanceCounters.cs
- ControlPersister.cs
- DecimalFormatter.cs
- StackOverflowException.cs