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
- EventDescriptor.cs
- DrawingState.cs
- Action.cs
- XmlSchemaAttribute.cs
- BatchParser.cs
- SByteConverter.cs
- Timer.cs
- CodeCompiler.cs
- Mappings.cs
- Model3DGroup.cs
- DateTimeConverter.cs
- ColumnHeader.cs
- BroadcastEventHelper.cs
- PeerHelpers.cs
- SafeHandle.cs
- SHA512CryptoServiceProvider.cs
- BufferedGraphicsContext.cs
- ColumnClickEvent.cs
- FontFamily.cs
- SEHException.cs
- AppDomainAttributes.cs
- ArrayElementGridEntry.cs
- XmlBufferReader.cs
- XmlSchemas.cs
- ItemCollection.cs
- Error.cs
- XmlEntity.cs
- SvcFileManager.cs
- TopClause.cs
- KnownTypeDataContractResolver.cs
- EmptyQuery.cs
- DbTypeMap.cs
- TransformPattern.cs
- InputMethodStateTypeInfo.cs
- SerializerDescriptor.cs
- RequestCachePolicyConverter.cs
- DesignerActionPropertyItem.cs
- CommunicationObjectManager.cs
- BoolExpression.cs
- WebServiceBindingAttribute.cs
- Converter.cs
- ModelPropertyImpl.cs
- SqlUtils.cs
- cookiecollection.cs
- DataGridItemEventArgs.cs
- FlowDocumentPaginator.cs
- StylusCollection.cs
- XmlSchemaDatatype.cs
- CodeDOMUtility.cs
- JournalNavigationScope.cs
- RemotingConfigParser.cs
- ProcessThreadCollection.cs
- SqlDataSourceDesigner.cs
- ReturnEventArgs.cs
- AlignmentXValidation.cs
- SqlBulkCopy.cs
- DataFormats.cs
- ListViewDesigner.cs
- ProfileEventArgs.cs
- CodeTypeParameter.cs
- ToolStripContentPanel.cs
- NativeMethodsCLR.cs
- GridViewRowPresenterBase.cs
- InternalPermissions.cs
- PhonemeEventArgs.cs
- BaseTemplateBuildProvider.cs
- Interfaces.cs
- LinqDataSource.cs
- JsonSerializer.cs
- PtsPage.cs
- Type.cs
- DebugView.cs
- Italic.cs
- KoreanLunisolarCalendar.cs
- RawStylusActions.cs
- SmtpDigestAuthenticationModule.cs
- RectangleGeometry.cs
- ListDictionaryInternal.cs
- XmlComplianceUtil.cs
- DesignerCategoryAttribute.cs
- SafeFileMappingHandle.cs
- ParallelRangeManager.cs
- SelectedGridItemChangedEvent.cs
- AppDomainFactory.cs
- PassportAuthenticationEventArgs.cs
- SessionStateUtil.cs
- DataGridViewColumnCollection.cs
- ProviderException.cs
- EditorAttribute.cs
- ChtmlLinkAdapter.cs
- EventArgs.cs
- DataSourceView.cs
- TdsParserStateObject.cs
- WindowsListViewGroup.cs
- PageWrapper.cs
- DbgUtil.cs
- SecurityHeaderTokenResolver.cs
- PersonalizationProviderCollection.cs
- DataStreams.cs
- TransformedBitmap.cs