Code:
/ 4.0 / 4.0 / untmp / 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
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlSchemaObject.cs
- AssemblyAttributes.cs
- TreeNodeCollection.cs
- SmiEventSink_DeferedProcessing.cs
- TrackingServices.cs
- BlurEffect.cs
- MergeFilterQuery.cs
- StrokeNodeOperations2.cs
- XPathDocumentNavigator.cs
- Script.cs
- CustomAttributeSerializer.cs
- DataList.cs
- GACIdentityPermission.cs
- FieldInfo.cs
- EntityDataSourceWizardForm.cs
- BaseDataBoundControlDesigner.cs
- WrapPanel.cs
- PathGeometry.cs
- DisplayMemberTemplateSelector.cs
- TextServicesDisplayAttribute.cs
- CompiledIdentityConstraint.cs
- WindowsAuthenticationModule.cs
- Triangle.cs
- DbUpdateCommandTree.cs
- BuiltInExpr.cs
- XmlAttributeAttribute.cs
- InvalidCastException.cs
- MarkupCompilePass2.cs
- ContourSegment.cs
- TraceProvider.cs
- TableChangeProcessor.cs
- ValidateNames.cs
- ApplicationGesture.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- CodeTypeParameter.cs
- _Events.cs
- WebPart.cs
- SafeHandle.cs
- MetadataArtifactLoaderResource.cs
- DbMetaDataFactory.cs
- ClientTargetCollection.cs
- XamlToRtfParser.cs
- EntityRecordInfo.cs
- NonPrimarySelectionGlyph.cs
- NonPrimarySelectionGlyph.cs
- VectorAnimationUsingKeyFrames.cs
- DataServiceConfiguration.cs
- AdPostCacheSubstitution.cs
- XmlSchemaException.cs
- UTF8Encoding.cs
- BlurBitmapEffect.cs
- RIPEMD160.cs
- DataGridTablesFactory.cs
- WebServiceTypeData.cs
- Win32.cs
- SqlFunctionAttribute.cs
- SqlClientFactory.cs
- Compress.cs
- CompilationUtil.cs
- OdbcConnectionOpen.cs
- OpCodes.cs
- XmlChildEnumerator.cs
- DataRecord.cs
- CollectionBuilder.cs
- Int32RectConverter.cs
- SamlAudienceRestrictionCondition.cs
- MemberAccessException.cs
- XmlDataCollection.cs
- MetadataItemEmitter.cs
- SiteMapProvider.cs
- TimeSpan.cs
- XmlSchema.cs
- EntityParameter.cs
- XmlFormatReaderGenerator.cs
- CustomAttribute.cs
- JulianCalendar.cs
- DataSysAttribute.cs
- TypedOperationInfo.cs
- ForwardPositionQuery.cs
- ObjectStateManager.cs
- ArgumentDesigner.xaml.cs
- ContextQuery.cs
- QilGeneratorEnv.cs
- SQLResource.cs
- MappingException.cs
- DetailsViewDeleteEventArgs.cs
- PerformanceCounterLib.cs
- XmlBaseReader.cs
- ListenerPerfCounters.cs
- SplineKeyFrames.cs
- NativeWindow.cs
- Events.cs
- TabControlToolboxItem.cs
- Rijndael.cs
- RenamedEventArgs.cs
- BulletedListEventArgs.cs
- ActivityBindForm.cs
- SqlNodeAnnotations.cs
- FormViewDeleteEventArgs.cs
- WebBrowser.cs