Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- CookieParameter.cs
- GlyphRun.cs
- KeyManager.cs
- SourceCollection.cs
- ResourceDisplayNameAttribute.cs
- StaticExtensionConverter.cs
- Registry.cs
- List.cs
- ParameterToken.cs
- VisualTreeHelper.cs
- Viewport3DVisual.cs
- Geometry.cs
- CannotUnloadAppDomainException.cs
- Grant.cs
- XmlSchemaDocumentation.cs
- SettingsPropertyNotFoundException.cs
- GZipUtils.cs
- MaskedTextProvider.cs
- WebBrowserUriTypeConverter.cs
- CultureTableRecord.cs
- XmlByteStreamReader.cs
- TraceSection.cs
- ProxyManager.cs
- CreateUserWizard.cs
- KeyInterop.cs
- MethodBuilder.cs
- CustomErrorsSectionWrapper.cs
- TypeHelper.cs
- TreeViewImageIndexConverter.cs
- PixelShader.cs
- FileSystemWatcher.cs
- LiteralControl.cs
- SQLChars.cs
- UserPreferenceChangedEventArgs.cs
- BindingObserver.cs
- TypeDescriptorFilterService.cs
- BlurBitmapEffect.cs
- Material.cs
- FileSystemInfo.cs
- XmlCollation.cs
- SchemaMapping.cs
- DragStartedEventArgs.cs
- SymbolMethod.cs
- InputLanguageEventArgs.cs
- RealProxy.cs
- AccessorTable.cs
- SQLInt64Storage.cs
- DataGridViewCheckBoxColumn.cs
- ViewCellRelation.cs
- InkCanvasSelectionAdorner.cs
- BridgeDataReader.cs
- RSAPKCS1SignatureFormatter.cs
- ArrayEditor.cs
- CodePropertyReferenceExpression.cs
- QuestionEventArgs.cs
- SaveWorkflowCommand.cs
- StorageMappingItemLoader.cs
- TextServicesCompartmentContext.cs
- ClientUrlResolverWrapper.cs
- LayoutExceptionEventArgs.cs
- XmlNotation.cs
- BodyGlyph.cs
- DrawingBrush.cs
- XmlDocument.cs
- WebSysDescriptionAttribute.cs
- XmlSchemaSubstitutionGroup.cs
- ExplicitDiscriminatorMap.cs
- SqlCommandSet.cs
- RegexFCD.cs
- IssuedTokenClientCredential.cs
- UrlMapping.cs
- PreparingEnlistment.cs
- ScriptResourceHandler.cs
- ChildTable.cs
- Subset.cs
- ClientRuntime.cs
- XmlNodeReader.cs
- SHA256.cs
- FlowDecisionDesigner.xaml.cs
- XmlSchemaParticle.cs
- FlowLayoutSettings.cs
- ReturnValue.cs
- PageClientProxyGenerator.cs
- ListViewAutomationPeer.cs
- TableItemProviderWrapper.cs
- Utilities.cs
- PersonalizableAttribute.cs
- BufferedWebEventProvider.cs
- ResolveNameEventArgs.cs
- WeakEventTable.cs
- NavigationProperty.cs
- ResourceKey.cs
- StyleSheetRefUrlEditor.cs
- IpcServerChannel.cs
- DataRowIndexBuffer.cs
- SqlRowUpdatedEvent.cs
- HwndSource.cs
- SimpleApplicationHost.cs
- ArrangedElementCollection.cs
- WebPartDeleteVerb.cs