Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / MS / Internal / BaseHashHelper.cs / 2 / 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 block list 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 block list 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
- SecurityManager.cs
- ToolboxItemImageConverter.cs
- ParseChildrenAsPropertiesAttribute.cs
- __ComObject.cs
- ListBoxAutomationPeer.cs
- ExtenderControl.cs
- MutexSecurity.cs
- SmiMetaData.cs
- CreateParams.cs
- PartialArray.cs
- AttributeAction.cs
- FlowDecisionDesigner.xaml.cs
- FormsAuthenticationUser.cs
- XPathNavigatorKeyComparer.cs
- MultiSelector.cs
- VectorCollectionValueSerializer.cs
- BadImageFormatException.cs
- TrackingAnnotationCollection.cs
- WebRequestModulesSection.cs
- ReadOnlyDataSource.cs
- EventNotify.cs
- ObjectDataSourceSelectingEventArgs.cs
- DocumentSchemaValidator.cs
- SequentialActivityDesigner.cs
- XPathDocumentNavigator.cs
- UpDownEvent.cs
- ByteAnimation.cs
- DataSourceXmlClassAttribute.cs
- ViewStateException.cs
- DataGridPageChangedEventArgs.cs
- ListBindingConverter.cs
- WindowsListView.cs
- ExtendedPropertyCollection.cs
- CoreSwitches.cs
- TypeConverterHelper.cs
- TypeConverterMarkupExtension.cs
- ProviderCommandInfoUtils.cs
- LocationSectionRecord.cs
- RtfControlWordInfo.cs
- LoadedOrUnloadedOperation.cs
- RawUIStateInputReport.cs
- DateTimeStorage.cs
- DataControlFieldHeaderCell.cs
- WebBrowserNavigatedEventHandler.cs
- ManipulationBoundaryFeedbackEventArgs.cs
- PolygonHotSpot.cs
- DesignTable.cs
- BreakRecordTable.cs
- DateRangeEvent.cs
- BrowsableAttribute.cs
- SQLGuid.cs
- ConfigXmlElement.cs
- BindingExpressionUncommonField.cs
- WebPartsSection.cs
- IIS7WorkerRequest.cs
- ProgressBar.cs
- MenuItem.cs
- x509utils.cs
- ScriptReference.cs
- RankException.cs
- FtpCachePolicyElement.cs
- CatalogZoneAutoFormat.cs
- IPEndPoint.cs
- COM2EnumConverter.cs
- DataGridItemEventArgs.cs
- CreationContext.cs
- QilSortKey.cs
- DetailsViewDeleteEventArgs.cs
- SqlRowUpdatedEvent.cs
- EmbeddedMailObjectsCollection.cs
- AndMessageFilter.cs
- StylusButton.cs
- BamlRecordHelper.cs
- ProfileServiceManager.cs
- HtmlForm.cs
- CDSCollectionETWBCLProvider.cs
- MimeParameterWriter.cs
- BoundsDrawingContextWalker.cs
- CodeArgumentReferenceExpression.cs
- BrushConverter.cs
- LexicalChunk.cs
- AutomationPattern.cs
- xmlfixedPageInfo.cs
- WebPartTransformerAttribute.cs
- ExclusiveTcpListener.cs
- CompressStream.cs
- comcontractssection.cs
- OrderingExpression.cs
- oledbconnectionstring.cs
- DataViewManagerListItemTypeDescriptor.cs
- FileSecurity.cs
- Mappings.cs
- CommonObjectSecurity.cs
- XPathException.cs
- GeneralTransformCollection.cs
- Main.cs
- ChangePassword.cs
- AnnotationComponentChooser.cs
- LogStream.cs
- DiscoveryDocument.cs