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
- MonthChangedEventArgs.cs
- AuthenticationModuleElementCollection.cs
- ForeignConstraint.cs
- ResourcePermissionBaseEntry.cs
- Image.cs
- SecurityTokenSerializer.cs
- WebControlsSection.cs
- Reference.cs
- InitialServerConnectionReader.cs
- TemplateManager.cs
- NamespaceDisplay.xaml.cs
- TimersDescriptionAttribute.cs
- PublisherIdentityPermission.cs
- PointKeyFrameCollection.cs
- DbModificationCommandTree.cs
- SchemaCollectionCompiler.cs
- DynamicDocumentPaginator.cs
- EmptyEnumerator.cs
- IntegerCollectionEditor.cs
- ComboBox.cs
- RtfFormatStack.cs
- WebConfigurationFileMap.cs
- UriWriter.cs
- LayoutUtils.cs
- GeometryModel3D.cs
- Section.cs
- CodeTypeParameter.cs
- BindingWorker.cs
- HtmlForm.cs
- SoapTransportImporter.cs
- CachedPathData.cs
- EntityDataSourceMemberPath.cs
- XPathPatternBuilder.cs
- ParallelTimeline.cs
- EdgeModeValidation.cs
- NativeMethods.cs
- EventWaitHandleSecurity.cs
- WmfPlaceableFileHeader.cs
- _ConnectStream.cs
- ColorConvertedBitmapExtension.cs
- CachedResourceDictionaryExtension.cs
- Margins.cs
- ColorTransform.cs
- DataServiceExpressionVisitor.cs
- ToolStripItemDataObject.cs
- CodeTypeDeclaration.cs
- HttpModuleAction.cs
- SeekableMessageNavigator.cs
- StylusButtonCollection.cs
- HttpConfigurationSystem.cs
- TemplateNameScope.cs
- WindowsTooltip.cs
- MoveSizeWinEventHandler.cs
- WindowsListViewScroll.cs
- OpenFileDialog.cs
- TypeDependencyAttribute.cs
- PopupRoot.cs
- HitTestParameters.cs
- Size.cs
- Pair.cs
- Utils.cs
- CqlBlock.cs
- StreamReader.cs
- BypassElement.cs
- DesignerActionVerbList.cs
- ContextStaticAttribute.cs
- Mappings.cs
- DesignerWithHeader.cs
- WebPartCancelEventArgs.cs
- ListBoxItemWrapperAutomationPeer.cs
- EventMappingSettingsCollection.cs
- CodeParameterDeclarationExpression.cs
- CngAlgorithmGroup.cs
- DirectoryObjectSecurity.cs
- MD5CryptoServiceProvider.cs
- ToolStripSettings.cs
- TreePrinter.cs
- XmlJsonWriter.cs
- CollectionViewGroupRoot.cs
- XmlChoiceIdentifierAttribute.cs
- PathSegmentCollection.cs
- TextParentUndoUnit.cs
- MultipartContentParser.cs
- XLinq.cs
- SendingRequestEventArgs.cs
- DataGridViewButtonColumn.cs
- Model3D.cs
- NotImplementedException.cs
- StateManagedCollection.cs
- WmlSelectionListAdapter.cs
- HebrewNumber.cs
- XPathItem.cs
- ConnectionProviderAttribute.cs
- PrivilegedConfigurationManager.cs
- EntityContainerAssociationSet.cs
- InstanceCreationEditor.cs
- IgnoreFlushAndCloseStream.cs
- MSAAEventDispatcher.cs
- IOException.cs
- XmlSchemaSequence.cs