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
- DetailsView.cs
- CellConstant.cs
- SapiAttributeParser.cs
- SelectionBorderGlyph.cs
- webeventbuffer.cs
- BufferedReadStream.cs
- ContainerCodeDomSerializer.cs
- InternalBufferOverflowException.cs
- WebControlParameterProxy.cs
- ListViewUpdatedEventArgs.cs
- WebPartManagerInternals.cs
- PackWebResponse.cs
- DrawListViewItemEventArgs.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- InputMethod.cs
- PopOutPanel.cs
- AppendHelper.cs
- PrintDialog.cs
- PreviewKeyDownEventArgs.cs
- Zone.cs
- PolyLineSegment.cs
- DataServices.cs
- TickBar.cs
- CharKeyFrameCollection.cs
- MaterializeFromAtom.cs
- TextTreePropertyUndoUnit.cs
- ExtentJoinTreeNode.cs
- QueryContinueDragEvent.cs
- WorkflowInstanceQuery.cs
- OpacityConverter.cs
- PackagePartCollection.cs
- TabPanel.cs
- QueryInterceptorAttribute.cs
- Asn1Utilities.cs
- ObjectReferenceStack.cs
- FileSystemEventArgs.cs
- RenderingBiasValidation.cs
- CompareValidator.cs
- EmbeddedObject.cs
- CryptoApi.cs
- SqlDataSourceStatusEventArgs.cs
- TemplatedMailWebEventProvider.cs
- GridLengthConverter.cs
- TimeoutException.cs
- ApplicationProxyInternal.cs
- SystemIPGlobalStatistics.cs
- NameSpaceEvent.cs
- MemberProjectionIndex.cs
- StringPropertyBuilder.cs
- ConsoleTraceListener.cs
- URLAttribute.cs
- HexParser.cs
- BaseDataBoundControl.cs
- HtmlTernaryTree.cs
- Queue.cs
- TransactionFilter.cs
- IsolatedStorageException.cs
- DragEvent.cs
- DodSequenceMerge.cs
- CriticalHandle.cs
- HTTPNotFoundHandler.cs
- TextSerializer.cs
- SqlEnums.cs
- diagnosticsswitches.cs
- ReadOnlyDictionary.cs
- DelegateHelpers.Generated.cs
- _SslState.cs
- StringDictionaryCodeDomSerializer.cs
- SystemIcons.cs
- StateDesigner.cs
- FixedSOMSemanticBox.cs
- RegexCharClass.cs
- CommentAction.cs
- SmtpReplyReaderFactory.cs
- Size.cs
- RuntimeCompatibilityAttribute.cs
- TrustManagerPromptUI.cs
- UnicastIPAddressInformationCollection.cs
- UIPropertyMetadata.cs
- TraceHandlerErrorFormatter.cs
- BitmapEncoder.cs
- Material.cs
- CacheAxisQuery.cs
- XPathDocumentIterator.cs
- indexingfiltermarshaler.cs
- SplayTreeNode.cs
- ResourceDictionaryCollection.cs
- FlowLayout.cs
- MiniAssembly.cs
- UserControl.cs
- CodeSubDirectoriesCollection.cs
- WebBrowserNavigatingEventHandler.cs
- SettingsPropertyNotFoundException.cs
- ThreadStartException.cs
- FieldAccessException.cs
- Point3DCollection.cs
- ExceptionHandlers.cs
- PrintingPermission.cs
- ClientFormsIdentity.cs
- EntityDataSourceContextCreatingEventArgs.cs