Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- MetafileHeaderWmf.cs
- EntityContainerAssociationSet.cs
- BaseTemplateParser.cs
- PageClientProxyGenerator.cs
- UnsafeNativeMethods.cs
- ToolStripItem.cs
- PermissionAttributes.cs
- ValidationEventArgs.cs
- DbConnectionHelper.cs
- WebServiceParameterData.cs
- XmlNullResolver.cs
- StyleTypedPropertyAttribute.cs
- SelectionEditor.cs
- WebEvents.cs
- JournalEntryStack.cs
- HtmlInputReset.cs
- MultiSelector.cs
- MobileErrorInfo.cs
- MD5CryptoServiceProvider.cs
- DesignerAutoFormatStyle.cs
- WebPartTransformer.cs
- ProfileEventArgs.cs
- ExpressionHelper.cs
- TypedMessageConverter.cs
- DocumentationServerProtocol.cs
- StorageScalarPropertyMapping.cs
- GeneralTransformGroup.cs
- DataPagerFieldItem.cs
- DivideByZeroException.cs
- UIntPtr.cs
- SymDocumentType.cs
- DataSourceExpression.cs
- FilterQueryOptionExpression.cs
- TypeDelegator.cs
- PenThreadWorker.cs
- XmlHierarchicalEnumerable.cs
- AuditLevel.cs
- DBCSCodePageEncoding.cs
- StateWorkerRequest.cs
- ObjectConverter.cs
- SQlBooleanStorage.cs
- Publisher.cs
- SqlVisitor.cs
- MatrixTransform3D.cs
- OleDbSchemaGuid.cs
- HtmlTableRow.cs
- TextDecorations.cs
- sqlpipe.cs
- X509Certificate.cs
- securitycriticaldata.cs
- InheritedPropertyChangedEventArgs.cs
- BooleanAnimationUsingKeyFrames.cs
- Style.cs
- RadioButtonStandardAdapter.cs
- MinimizableAttributeTypeConverter.cs
- CapabilitiesPattern.cs
- ButtonBase.cs
- InternalBufferOverflowException.cs
- WebBrowserPermission.cs
- LayoutSettings.cs
- FirstMatchCodeGroup.cs
- DropDownButton.cs
- RecordConverter.cs
- ScriptManagerProxy.cs
- OleDbSchemaGuid.cs
- BoundsDrawingContextWalker.cs
- BaseDataListActionList.cs
- InputLangChangeEvent.cs
- SliderAutomationPeer.cs
- WebConfigurationHost.cs
- VSWCFServiceContractGenerator.cs
- XmlDataProvider.cs
- SimpleLine.cs
- TaskDesigner.cs
- VerifyHashRequest.cs
- CollectionViewProxy.cs
- SafeNativeMethods.cs
- XmlSchemaComplexContentRestriction.cs
- Stream.cs
- AlignmentXValidation.cs
- StreamResourceInfo.cs
- XmlSchemaNotation.cs
- Win32Exception.cs
- Viewport3DVisual.cs
- CodeCompiler.cs
- SchemaTypeEmitter.cs
- RuntimeHandles.cs
- HttpVersion.cs
- PageSettings.cs
- CodeValidator.cs
- PenThread.cs
- ModelEditingScope.cs
- KeyboardEventArgs.cs
- DataSourceView.cs
- EFDataModelProvider.cs
- GradientStop.cs
- TCEAdapterGenerator.cs
- Table.cs
- DataListItemEventArgs.cs
- TextSelectionProcessor.cs