Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Misc / CompatibleIComparer.cs / 1305376 / 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
- RunClient.cs
- InternalBufferOverflowException.cs
- ResizeGrip.cs
- PrimitiveXmlSerializers.cs
- Attributes.cs
- GeneratedContractType.cs
- ProviderSettingsCollection.cs
- BufferedOutputStream.cs
- ListCommandEventArgs.cs
- ControlBindingsCollection.cs
- ConsoleKeyInfo.cs
- TypedReference.cs
- RectAnimationUsingKeyFrames.cs
- OdbcParameter.cs
- AssociationSet.cs
- DataSysAttribute.cs
- TextBoxAutoCompleteSourceConverter.cs
- XNodeValidator.cs
- TypeExtensionConverter.cs
- NetStream.cs
- HMACSHA1.cs
- ToolStripTextBox.cs
- XamlGridLengthSerializer.cs
- ResourceExpressionBuilder.cs
- SimpleApplicationHost.cs
- ResourceReferenceExpression.cs
- ContextMenuService.cs
- DataGridViewTopRowAccessibleObject.cs
- ColumnTypeConverter.cs
- _ContextAwareResult.cs
- XPathEmptyIterator.cs
- BufferBuilder.cs
- ComponentEditorForm.cs
- PreviewPrintController.cs
- ToolStripDropDownClosingEventArgs.cs
- FormatVersion.cs
- CmsUtils.cs
- ToolStripOverflowButton.cs
- RightsManagementPermission.cs
- ListViewDeleteEventArgs.cs
- MultiSelector.cs
- PagedControl.cs
- DeferrableContentConverter.cs
- XmlImplementation.cs
- IImplicitResourceProvider.cs
- ReachUIElementCollectionSerializer.cs
- XmlQualifiedName.cs
- HttpStreamXmlDictionaryReader.cs
- GeometryCombineModeValidation.cs
- MapPathBasedVirtualPathProvider.cs
- SqlXml.cs
- CustomAttributeBuilder.cs
- DetailsViewPagerRow.cs
- CodeEntryPointMethod.cs
- XNodeNavigator.cs
- Int32.cs
- TreeNodeConverter.cs
- TextElementEnumerator.cs
- ValueExpressions.cs
- UpdateProgress.cs
- WebControl.cs
- CroppedBitmap.cs
- GridViewCommandEventArgs.cs
- BitmapSourceSafeMILHandle.cs
- ControlBuilder.cs
- safelink.cs
- NavigationPropertyAccessor.cs
- Serializer.cs
- SafeRightsManagementHandle.cs
- TableDesigner.cs
- DataSourceControl.cs
- RegexTypeEditor.cs
- COM2ExtendedUITypeEditor.cs
- XmlCharCheckingWriter.cs
- DropDownList.cs
- ActiveDocumentEvent.cs
- SymDocumentType.cs
- DPAPIProtectedConfigurationProvider.cs
- FamilyTypeface.cs
- ISFClipboardData.cs
- DataProtection.cs
- BrowserDefinitionCollection.cs
- InternalDispatchObject.cs
- ThaiBuddhistCalendar.cs
- MsmqBindingBase.cs
- TextEditorLists.cs
- OdbcException.cs
- Mutex.cs
- StreamWriter.cs
- TriggerBase.cs
- ChannelProtectionRequirements.cs
- FormatConvertedBitmap.cs
- ImmutableCollection.cs
- DbConnectionFactory.cs
- Base64Decoder.cs
- OdbcParameter.cs
- Line.cs
- TemplateKeyConverter.cs
- DataListItemCollection.cs
- ActivityDesignerAccessibleObject.cs