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
- BufferBuilder.cs
- SortAction.cs
- MethodBuilderInstantiation.cs
- SqlReferenceCollection.cs
- LogReservationCollection.cs
- TabletDeviceInfo.cs
- AssociatedControlConverter.cs
- ImageAnimator.cs
- SqlMethodAttribute.cs
- StringUtil.cs
- ConfigLoader.cs
- WinFormsComponentEditor.cs
- PropertyRecord.cs
- ObjectStorage.cs
- _CommandStream.cs
- ToolZone.cs
- ProtectedProviderSettings.cs
- StringPropertyBuilder.cs
- StringUtil.cs
- ContextMenuStripActionList.cs
- EntityDataSourceView.cs
- Literal.cs
- XmlDataContract.cs
- FixedPosition.cs
- JsonGlobals.cs
- Trace.cs
- CodeAttributeDeclarationCollection.cs
- GridViewRowPresenter.cs
- WizardDesigner.cs
- ReferencedType.cs
- LinkConverter.cs
- EnterpriseServicesHelper.cs
- CommandHelpers.cs
- ListControlDesigner.cs
- XsltSettings.cs
- RsaSecurityToken.cs
- EndOfStreamException.cs
- OrthographicCamera.cs
- RegexCapture.cs
- Environment.cs
- DesignerActionList.cs
- TouchFrameEventArgs.cs
- RNGCryptoServiceProvider.cs
- ImageKeyConverter.cs
- FileAuthorizationModule.cs
- TreeNodeCollection.cs
- EpmSourceTree.cs
- DoubleConverter.cs
- TimeSpanConverter.cs
- Expressions.cs
- Graphics.cs
- TextChangedEventArgs.cs
- AuthenticationConfig.cs
- InspectionWorker.cs
- HttpServerUtilityWrapper.cs
- FileNotFoundException.cs
- UnmanagedMarshal.cs
- FormViewPagerRow.cs
- Transform3D.cs
- EntityCollection.cs
- WizardForm.cs
- TextHintingModeValidation.cs
- RequestValidator.cs
- ScrollItemPattern.cs
- ListDictionary.cs
- IndependentAnimationStorage.cs
- SystemException.cs
- LambdaCompiler.ControlFlow.cs
- DataGridViewCellStyle.cs
- TextSegment.cs
- AssociatedControlConverter.cs
- DateTimePicker.cs
- ExecutedRoutedEventArgs.cs
- ControlHelper.cs
- RequestQueryProcessor.cs
- _SecureChannel.cs
- Calendar.cs
- StringCollection.cs
- ReflectPropertyDescriptor.cs
- PageCanvasSize.cs
- MetadataStore.cs
- SecurityManager.cs
- TextCharacters.cs
- Invariant.cs
- Win32Native.cs
- PageParserFilter.cs
- SqlConnectionHelper.cs
- RegexNode.cs
- EntityException.cs
- DataErrorValidationRule.cs
- ReflectionUtil.cs
- Error.cs
- WebServiceHandler.cs
- InternalCompensate.cs
- FileDialogCustomPlace.cs
- PrintDocument.cs
- HostedTransportConfigurationBase.cs
- TextElementEnumerator.cs
- WindowsListViewItemCheckBox.cs
- XmlProcessingInstruction.cs