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
- DataGridCellItemAutomationPeer.cs
- GenericIdentity.cs
- ClientSideProviderDescription.cs
- ContextMenuAutomationPeer.cs
- DataGridView.cs
- TraceXPathNavigator.cs
- ActivationArguments.cs
- HttpAsyncResult.cs
- PropertyStore.cs
- InnerItemCollectionView.cs
- CompoundFileStorageReference.cs
- AtomMaterializerLog.cs
- Debugger.cs
- NativeMethods.cs
- ObjectRef.cs
- DiagnosticTraceSource.cs
- SQLSingleStorage.cs
- DataGridViewColumn.cs
- CompareValidator.cs
- ActivityInstanceReference.cs
- RuntimeConfigLKG.cs
- FixedPageProcessor.cs
- XmlDictionaryReader.cs
- FixedSOMLineCollection.cs
- TableLayoutSettings.cs
- StdValidatorsAndConverters.cs
- UserMapPath.cs
- GridSplitterAutomationPeer.cs
- ServiceProviders.cs
- SqlRewriteScalarSubqueries.cs
- HtmlLink.cs
- WebBrowserHelper.cs
- XamlClipboardData.cs
- ButtonFlatAdapter.cs
- OdbcConnectionStringbuilder.cs
- SqlDependency.cs
- ArraySegment.cs
- SiteMembershipCondition.cs
- XmlAutoDetectWriter.cs
- CellConstantDomain.cs
- DesignSurfaceCollection.cs
- OdbcConnectionHandle.cs
- LeftCellWrapper.cs
- StrokeDescriptor.cs
- LocalValueEnumerator.cs
- TransformerInfoCollection.cs
- OleDbError.cs
- TemplateKey.cs
- SerializationFieldInfo.cs
- OleDbErrorCollection.cs
- ListControlBuilder.cs
- contentDescriptor.cs
- KeyValueSerializer.cs
- InvalidCommandTreeException.cs
- WindowsEditBoxRange.cs
- TypeUsageBuilder.cs
- TextServicesCompartmentEventSink.cs
- ProxySimple.cs
- FunctionCommandText.cs
- GroupLabel.cs
- StickyNoteAnnotations.cs
- SvcMapFileSerializer.cs
- Misc.cs
- DebugHandleTracker.cs
- ReachDocumentReferenceCollectionSerializerAsync.cs
- GenericAuthenticationEventArgs.cs
- FigureHelper.cs
- WebRequest.cs
- WebBrowserNavigatingEventHandler.cs
- DataRecordInternal.cs
- TreeNodeStyle.cs
- EncryptedType.cs
- XmlAttributeCache.cs
- ImageAttributes.cs
- ClientSettingsStore.cs
- SimpleType.cs
- SchemaTypeEmitter.cs
- SignatureGenerator.cs
- TriState.cs
- EncodingInfo.cs
- ImageButton.cs
- GregorianCalendarHelper.cs
- XmlSchemaSimpleContent.cs
- FormatterServices.cs
- PiiTraceSource.cs
- CommonGetThemePartSize.cs
- SafeViewOfFileHandle.cs
- BamlLocalizer.cs
- DataGridToolTip.cs
- TrackBarRenderer.cs
- SignatureToken.cs
- StartUpEventArgs.cs
- Exceptions.cs
- SignerInfo.cs
- ListViewItem.cs
- DbTypeMap.cs
- SqlLiftIndependentRowExpressions.cs
- LocalizationParserHooks.cs
- Rfc2898DeriveBytes.cs
- DependencyPropertyHelper.cs