Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / BaseHashHelper.cs / 1305600 / 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) { 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) { 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
- ComponentEditorForm.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- Matrix.cs
- PropertyPath.cs
- MarginCollapsingState.cs
- ResumeStoryboard.cs
- RNGCryptoServiceProvider.cs
- WebPartAuthorizationEventArgs.cs
- Listbox.cs
- ObjectDataSourceSelectingEventArgs.cs
- Choices.cs
- LambdaCompiler.Logical.cs
- BlockCollection.cs
- GeometryGroup.cs
- XsltConvert.cs
- DiscoveryMessageSequenceGenerator.cs
- RequiredFieldValidator.cs
- TemplateField.cs
- SiteMapNode.cs
- InvalidDataException.cs
- BasePropertyDescriptor.cs
- DataObjectSettingDataEventArgs.cs
- DataControlFieldHeaderCell.cs
- BindStream.cs
- SortAction.cs
- SiteMapDataSourceDesigner.cs
- FormViewInsertEventArgs.cs
- ProtocolViolationException.cs
- PolyLineSegment.cs
- BlurBitmapEffect.cs
- MultiPropertyDescriptorGridEntry.cs
- InternalCache.cs
- ToolStripGrip.cs
- _NestedMultipleAsyncResult.cs
- TimeSpanValidatorAttribute.cs
- PropertyDescriptorComparer.cs
- MetaType.cs
- WrapPanel.cs
- DataKey.cs
- SqlParameterizer.cs
- RepeaterItemEventArgs.cs
- SqlSupersetValidator.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- WebPartVerbCollection.cs
- BuildProviderAppliesToAttribute.cs
- FontCacheLogic.cs
- OutputCacheModule.cs
- DelegatingConfigHost.cs
- PenContext.cs
- ColorDialog.cs
- recordstate.cs
- Point3DCollection.cs
- ConvertBinder.cs
- TraceContextEventArgs.cs
- TrackBarRenderer.cs
- ExcCanonicalXml.cs
- LocationUpdates.cs
- Lasso.cs
- CompilerGeneratedAttribute.cs
- BaseAsyncResult.cs
- _HeaderInfoTable.cs
- TypedTableBaseExtensions.cs
- MarkupProperty.cs
- IdleTimeoutMonitor.cs
- CriticalFinalizerObject.cs
- NativeCppClassAttribute.cs
- XmlLoader.cs
- ColorTranslator.cs
- SectionInput.cs
- URLAttribute.cs
- StreamMarshaler.cs
- CapabilitiesAssignment.cs
- SafeFileMapViewHandle.cs
- CapabilitiesPattern.cs
- ReflectionHelper.cs
- DependencyObjectType.cs
- BulletChrome.cs
- GeometryHitTestResult.cs
- XmlDocument.cs
- ItemsChangedEventArgs.cs
- SqlDataSourceStatusEventArgs.cs
- ConfigurationSectionCollection.cs
- StandardCommands.cs
- SmiMetaDataProperty.cs
- XmlStreamStore.cs
- ToolStripPanelRenderEventArgs.cs
- DataGridViewBindingCompleteEventArgs.cs
- ToolStripButton.cs
- PersistChildrenAttribute.cs
- PrimitiveDataContract.cs
- ITreeGenerator.cs
- TextElementAutomationPeer.cs
- BitmapScalingModeValidation.cs
- ActionFrame.cs
- Animatable.cs
- SqlCacheDependency.cs
- ObfuscateAssemblyAttribute.cs
- XmlnsDefinitionAttribute.cs
- XNodeValidator.cs
- DataGridViewRowPostPaintEventArgs.cs