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
- PagePropertiesChangingEventArgs.cs
- ObjectItemCachedAssemblyLoader.cs
- DrawingGroup.cs
- Decoder.cs
- SoapElementAttribute.cs
- XmlQualifiedName.cs
- NamespaceEmitter.cs
- CodeDirectoryCompiler.cs
- StringAnimationBase.cs
- HelpInfo.cs
- IPPacketInformation.cs
- XslTransform.cs
- DefaultObjectMappingItemCollection.cs
- MaxValueConverter.cs
- HostSecurityManager.cs
- Attributes.cs
- Expressions.cs
- SchemaRegistration.cs
- ActiveXSite.cs
- DefaultSection.cs
- PnrpPermission.cs
- DataSysAttribute.cs
- ToolStripDesignerUtils.cs
- XmlDataDocument.cs
- ReadOnlyNameValueCollection.cs
- PropertyTab.cs
- SelectedDatesCollection.cs
- AspNetRouteServiceHttpHandler.cs
- ExtendedProperty.cs
- UnsafeNativeMethods.cs
- Int32CAMarshaler.cs
- SamlSecurityToken.cs
- TextEditorMouse.cs
- Geometry3D.cs
- RegionIterator.cs
- CfgParser.cs
- AssociationSetEnd.cs
- Trace.cs
- Permission.cs
- LinqToSqlWrapper.cs
- EventArgs.cs
- _SpnDictionary.cs
- Ops.cs
- xmlglyphRunInfo.cs
- WebPartZoneBase.cs
- PrintControllerWithStatusDialog.cs
- XpsDocumentEvent.cs
- EnumMember.cs
- X509PeerCertificateAuthenticationElement.cs
- DesignerActionHeaderItem.cs
- OciEnlistContext.cs
- ExceptionList.cs
- BufferedWebEventProvider.cs
- XmlTypeMapping.cs
- SRGSCompiler.cs
- FixedDSBuilder.cs
- DescendentsWalker.cs
- SafeSecurityHandles.cs
- ConvertEvent.cs
- TableDetailsCollection.cs
- PackUriHelper.cs
- EventLogPermissionEntry.cs
- HelpInfo.cs
- DbQueryCommandTree.cs
- Label.cs
- X509Utils.cs
- DesignerOptions.cs
- DataGridColumnCollection.cs
- CqlErrorHelper.cs
- WSIdentityFaultException.cs
- FtpCachePolicyElement.cs
- DateTimeStorage.cs
- DataGridRow.cs
- ResourcesGenerator.cs
- IPCCacheManager.cs
- MetadataProperty.cs
- DynamicResourceExtensionConverter.cs
- ResourceSet.cs
- SecurityProtocol.cs
- WebDescriptionAttribute.cs
- ConsoleCancelEventArgs.cs
- assemblycache.cs
- SynchronizedChannelCollection.cs
- CircleHotSpot.cs
- ObjectDataProvider.cs
- MimeXmlReflector.cs
- SortQuery.cs
- ScriptMethodAttribute.cs
- CallbackException.cs
- WorkflowItemsPresenter.cs
- ETagAttribute.cs
- Converter.cs
- FamilyMapCollection.cs
- StringExpressionSet.cs
- Utils.cs
- GroupDescription.cs
- CircleHotSpot.cs
- XsdBuildProvider.cs
- PolyQuadraticBezierSegment.cs
- PerspectiveCamera.cs