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
- IsolatedStorage.cs
- TimelineGroup.cs
- FlowDocumentPage.cs
- WeakReferenceList.cs
- Helpers.cs
- IDQuery.cs
- RenderDataDrawingContext.cs
- ETagAttribute.cs
- EntityDataSource.cs
- InfiniteIntConverter.cs
- ComponentManagerBroker.cs
- ResourceDescriptionAttribute.cs
- Rotation3D.cs
- ObjectManager.cs
- PrintController.cs
- ObjectSet.cs
- UserControlParser.cs
- Page.cs
- Fonts.cs
- SoapElementAttribute.cs
- Journaling.cs
- OdbcEnvironment.cs
- EmbossBitmapEffect.cs
- FuncCompletionCallbackWrapper.cs
- ReturnType.cs
- Package.cs
- Boolean.cs
- JoinElimination.cs
- HwndKeyboardInputProvider.cs
- SchemaComplexType.cs
- SignedPkcs7.cs
- ListBoxItem.cs
- EventRoute.cs
- DataSourceConverter.cs
- WindowsAuthenticationModule.cs
- PointConverter.cs
- XmlSchemaDocumentation.cs
- IntPtr.cs
- Update.cs
- DataGridTablesFactory.cs
- Rectangle.cs
- DbReferenceCollection.cs
- OperationGenerator.cs
- SpinWait.cs
- Button.cs
- CompositeActivityTypeDescriptor.cs
- MenuItemStyle.cs
- ModelTreeEnumerator.cs
- SyndicationSerializer.cs
- ConfigurationLocation.cs
- NetPeerTcpBinding.cs
- GlyphRunDrawing.cs
- ContainerParaClient.cs
- UnsafeCollabNativeMethods.cs
- XmlValidatingReaderImpl.cs
- QilLiteral.cs
- DESCryptoServiceProvider.cs
- VersionedStreamOwner.cs
- ProgramPublisher.cs
- XmlElementAttributes.cs
- CompilerResults.cs
- TransactionBehavior.cs
- ForwardPositionQuery.cs
- EnumMemberAttribute.cs
- MaterializeFromAtom.cs
- FixedSOMPageElement.cs
- RetriableClipboard.cs
- ObjectSet.cs
- NativeRecognizer.cs
- HandlerBase.cs
- CodeSubDirectory.cs
- DbProviderSpecificTypePropertyAttribute.cs
- Buffer.cs
- IDispatchConstantAttribute.cs
- ToolStripSystemRenderer.cs
- ReferentialConstraint.cs
- ListViewTableCell.cs
- XPathBinder.cs
- HttpListenerRequest.cs
- LinqDataSourceDisposeEventArgs.cs
- FilteredSchemaElementLookUpTable.cs
- XmlnsCache.cs
- Effect.cs
- WarningException.cs
- XmlArrayItemAttributes.cs
- DbBuffer.cs
- NativeMethods.cs
- HtmlForm.cs
- PtsHelper.cs
- ClientSponsor.cs
- QueryOpeningEnumerator.cs
- ToolTipAutomationPeer.cs
- TraceHwndHost.cs
- MatrixKeyFrameCollection.cs
- ProcessHostServerConfig.cs
- DoubleAnimationBase.cs
- Exceptions.cs
- CreateSequenceResponse.cs
- BamlBinaryReader.cs
- _LocalDataStore.cs