Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- CollectionViewProxy.cs
- Tuple.cs
- AssemblyAttributes.cs
- RegistryPermission.cs
- CallContext.cs
- SiteMapNode.cs
- OleDbConnection.cs
- oledbmetadatacollectionnames.cs
- Array.cs
- ColorPalette.cs
- AuthStoreRoleProvider.cs
- WSHttpBindingBaseElement.cs
- ControlBindingsCollection.cs
- GeneralTransformGroup.cs
- GPPOINT.cs
- ToolStripDropDownMenu.cs
- DataServiceQueryProvider.cs
- GenericIdentity.cs
- XmlHelper.cs
- WorkflowMarkupSerializationProvider.cs
- OdbcEnvironment.cs
- EntityCommandCompilationException.cs
- EntryPointNotFoundException.cs
- WindowsToolbarItemAsMenuItem.cs
- ContextStack.cs
- SoapFaultCodes.cs
- TraceListeners.cs
- SerialReceived.cs
- RegexTree.cs
- CachedRequestParams.cs
- CryptoStream.cs
- WaitHandle.cs
- ByteConverter.cs
- LabelDesigner.cs
- ScaleTransform3D.cs
- ProfileGroupSettingsCollection.cs
- XmlUtilWriter.cs
- SystemFonts.cs
- TimeSpanMinutesConverter.cs
- SamlSecurityToken.cs
- PieceNameHelper.cs
- InheritanceAttribute.cs
- SafeNativeMethods.cs
- ContainerAction.cs
- Propagator.ExtentPlaceholderCreator.cs
- AdjustableArrowCap.cs
- PipeException.cs
- PropertyTabAttribute.cs
- CheckBox.cs
- SafeReadContext.cs
- BufferedReceiveElement.cs
- ConfigurationPermission.cs
- PropertyChangedEventManager.cs
- RegexNode.cs
- TriggerCollection.cs
- XPathParser.cs
- SafeEventLogWriteHandle.cs
- DefinitionUpdate.cs
- SupportsEventValidationAttribute.cs
- URLIdentityPermission.cs
- ValidationRuleCollection.cs
- TextServicesManager.cs
- HighContrastHelper.cs
- InvokeMethodActivity.cs
- OneOfScalarConst.cs
- HGlobalSafeHandle.cs
- CompilerInfo.cs
- HtmlLink.cs
- IsolatedStorage.cs
- Color.cs
- XmlCompatibilityReader.cs
- ItemType.cs
- QuaternionRotation3D.cs
- ContentFilePart.cs
- ToolZone.cs
- QilFactory.cs
- MatchingStyle.cs
- DocumentSequenceHighlightLayer.cs
- RuntimeComponentFilter.cs
- CheckStoreFileValidityRequest.cs
- MappedMetaModel.cs
- InputLangChangeRequestEvent.cs
- ZipIOCentralDirectoryFileHeader.cs
- WindowAutomationPeer.cs
- GZipDecoder.cs
- _TimerThread.cs
- QueryCacheEntry.cs
- CompressEmulationStream.cs
- _AutoWebProxyScriptHelper.cs
- TextTrailingCharacterEllipsis.cs
- IssuanceLicense.cs
- VirtualizingPanel.cs
- Comparer.cs
- ETagAttribute.cs
- unsafenativemethodsother.cs
- BypassElementCollection.cs
- DbConnectionFactory.cs
- SatelliteContractVersionAttribute.cs
- ExpressionVisitor.cs
- ZipIOLocalFileBlock.cs