Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Misc / CompatibleIComparer.cs / 1 / CompatibleIComparer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * This class is used to create hashcodes that are Everett Compatible. * * Copyright (c) 2004 Microsoft Corporation */ namespace System.Collections.Specialized { using Microsoft.Win32; using System.Collections; using System.Runtime.Serialization; using System.Globalization; internal class BackCompatibleStringComparer : IEqualityComparer { static internal IEqualityComparer Default = new BackCompatibleStringComparer(); internal BackCompatibleStringComparer() { } //This comes from VS# 434837 and is specifically written to get backcompat public static int GetHashCode(string obj) { unsafe { fixed (char* src = obj) { int hash = 5381; int c; char* szStr = src; while ((c = *szStr) != 0) { hash = ((hash << 5) + hash) ^ c; ++szStr; } return hash; } } } bool IEqualityComparer.Equals(Object a, Object b) { return Object.Equals(a, b); } public virtual int GetHashCode(Object o) { String obj = o as string; if (obj == null) { return o.GetHashCode(); } return BackCompatibleStringComparer.GetHashCode(obj); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * This class is used to create hashcodes that are Everett Compatible. * * Copyright (c) 2004 Microsoft Corporation */ namespace System.Collections.Specialized { using Microsoft.Win32; using System.Collections; using System.Runtime.Serialization; using System.Globalization; internal class BackCompatibleStringComparer : IEqualityComparer { static internal IEqualityComparer Default = new BackCompatibleStringComparer(); internal BackCompatibleStringComparer() { } //This comes from VS# 434837 and is specifically written to get backcompat public static int GetHashCode(string obj) { unsafe { fixed (char* src = obj) { int hash = 5381; int c; char* szStr = src; while ((c = *szStr) != 0) { hash = ((hash << 5) + hash) ^ c; ++szStr; } return hash; } } } bool IEqualityComparer.Equals(Object a, Object b) { return Object.Equals(a, b); } public virtual int GetHashCode(Object o) { String obj = o as string; if (obj == null) { return o.GetHashCode(); } return BackCompatibleStringComparer.GetHashCode(obj); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- loginstatus.cs
- ToolBarButton.cs
- ImageListStreamer.cs
- StringFormat.cs
- ReadOnlyNameValueCollection.cs
- ResourceReferenceExpressionConverter.cs
- CheckBoxFlatAdapter.cs
- ProtocolsConfigurationHandler.cs
- ApplicationException.cs
- XLinq.cs
- CodeLabeledStatement.cs
- X500Name.cs
- ToolStripItem.cs
- DesignConnection.cs
- ReadOnlyDictionary.cs
- DataServiceQueryException.cs
- SystemDropShadowChrome.cs
- RuleAttributes.cs
- SaveFileDialog.cs
- CodeGotoStatement.cs
- FileDialog_Vista.cs
- BamlLocalizableResource.cs
- WinFormsUtils.cs
- UnsafeNativeMethods.cs
- WindowsListViewItemCheckBox.cs
- VisualStyleInformation.cs
- BCryptHashAlgorithm.cs
- BinaryCommonClasses.cs
- XmlTextReaderImpl.cs
- AssociationTypeEmitter.cs
- CodeGenerator.cs
- SyndicationElementExtensionCollection.cs
- ForceCopyBuildProvider.cs
- SystemColorTracker.cs
- _ProxyChain.cs
- Coordinator.cs
- TextEditorTyping.cs
- ViewManagerAttribute.cs
- BlockUIContainer.cs
- WinFormsUtils.cs
- SortedDictionary.cs
- HtmlInputPassword.cs
- Ref.cs
- VisualStyleInformation.cs
- FileLevelControlBuilderAttribute.cs
- TextParagraphProperties.cs
- WebBaseEventKeyComparer.cs
- FontStretch.cs
- CommonXSendMessage.cs
- FormViewUpdateEventArgs.cs
- DelegateOutArgument.cs
- CopyAttributesAction.cs
- FrameworkElement.cs
- MinMaxParagraphWidth.cs
- BamlResourceSerializer.cs
- TabControlCancelEvent.cs
- EntityConnection.cs
- Figure.cs
- XslNumber.cs
- TextModifier.cs
- ObjectDataSourceDesigner.cs
- BuildManager.cs
- ValidationPropertyAttribute.cs
- Msec.cs
- FactoryMaker.cs
- Pens.cs
- MarkerProperties.cs
- PackageFilter.cs
- DiscoveryDocumentSearchPattern.cs
- HandlerElementCollection.cs
- DataGridCommandEventArgs.cs
- CustomCategoryAttribute.cs
- CompilationPass2Task.cs
- SafeViewOfFileHandle.cs
- Deflater.cs
- AppDomainProtocolHandler.cs
- FieldAccessException.cs
- WebMessageBodyStyleHelper.cs
- PropertiesTab.cs
- graph.cs
- SqlDataSourceCommandEventArgs.cs
- ValidationErrorCollection.cs
- Header.cs
- SerializerDescriptor.cs
- ItemChangedEventArgs.cs
- HScrollBar.cs
- ExpressionHelper.cs
- CustomValidator.cs
- EntityViewGenerator.cs
- UnsafeNativeMethodsTablet.cs
- ReflectEventDescriptor.cs
- SafeNativeMethods.cs
- _SslState.cs
- RoleManagerEventArgs.cs
- PropertyMappingExceptionEventArgs.cs
- Enlistment.cs
- KeyMatchBuilder.cs
- RtType.cs
- QueryContinueDragEvent.cs
- SiteMembershipCondition.cs