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
- PageTrueTypeFont.cs
- GetPageCompletedEventArgs.cs
- ConditionValidator.cs
- basemetadatamappingvisitor.cs
- WindowsAltTab.cs
- ContainerActivationHelper.cs
- SetterBase.cs
- BitmapFrameEncode.cs
- StructuralObject.cs
- DefaultSerializationProviderAttribute.cs
- SpecialFolderEnumConverter.cs
- AppModelKnownContentFactory.cs
- Selection.cs
- OperationAbortedException.cs
- TreeNodeClickEventArgs.cs
- MailHeaderInfo.cs
- TextParagraph.cs
- EventLogPermissionHolder.cs
- _AcceptOverlappedAsyncResult.cs
- ToolBarButtonClickEvent.cs
- StatusBarPanel.cs
- PrinterUnitConvert.cs
- SerializationSectionGroup.cs
- RegexCompilationInfo.cs
- ExtensionElement.cs
- MyContact.cs
- ConnectionManagementElementCollection.cs
- Window.cs
- CodeIdentifier.cs
- CreateUserErrorEventArgs.cs
- EncoderFallback.cs
- DocumentPageView.cs
- Int32Rect.cs
- RSAOAEPKeyExchangeDeformatter.cs
- CodeArgumentReferenceExpression.cs
- BitmapEditor.cs
- WebRequestModulesSection.cs
- XmlEncodedRawTextWriter.cs
- BoolExpr.cs
- activationcontext.cs
- UnsafeNativeMethods.cs
- ObjectDataProvider.cs
- TextDecoration.cs
- PeerNameRegistration.cs
- TypeUtils.cs
- CredentialManagerDialog.cs
- PageBuildProvider.cs
- BaseTemplateParser.cs
- TextFindEngine.cs
- IdentityValidationException.cs
- TraceData.cs
- ProviderCommandInfoUtils.cs
- ToolboxCategory.cs
- Padding.cs
- DoubleAnimationClockResource.cs
- HostExecutionContextManager.cs
- StateMachineSubscription.cs
- Wizard.cs
- BindingExpression.cs
- QueryOpeningEnumerator.cs
- FixedSOMPage.cs
- SpinLock.cs
- ScrollViewerAutomationPeer.cs
- VirtualPath.cs
- DateTimeConverter.cs
- ArgIterator.cs
- ConnectionProviderAttribute.cs
- RelationshipNavigation.cs
- BindStream.cs
- BooleanAnimationBase.cs
- ParsedRoute.cs
- PolicyManager.cs
- TextServicesCompartment.cs
- ScrollViewer.cs
- Matrix3DStack.cs
- Menu.cs
- Table.cs
- SystemNetworkInterface.cs
- TreeViewDesigner.cs
- SqlExpander.cs
- EdmScalarPropertyAttribute.cs
- SqlInternalConnection.cs
- Instrumentation.cs
- StringFormat.cs
- RenderDataDrawingContext.cs
- HtmlHistory.cs
- ErrorWebPart.cs
- ListBase.cs
- codemethodreferenceexpression.cs
- CookieParameter.cs
- XmlChoiceIdentifierAttribute.cs
- WizardSideBarListControlItem.cs
- webclient.cs
- Globals.cs
- HttpHandlerAction.cs
- SqlProviderServices.cs
- ConditionalAttribute.cs
- DbConnectionPoolCounters.cs
- RelatedEnd.cs
- UnaryNode.cs