Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- RowBinding.cs
- ReadOnlyCollectionBase.cs
- ClientSession.cs
- VersionPair.cs
- ConfigXmlCDataSection.cs
- SafeFileMappingHandle.cs
- SafeArrayTypeMismatchException.cs
- UInt16Converter.cs
- ProfilePropertyNameValidator.cs
- CssTextWriter.cs
- WindowsHyperlink.cs
- SerialPinChanges.cs
- DataContractSerializerFaultFormatter.cs
- EntityDataSourceWrapperCollection.cs
- StateMachineAction.cs
- ThreadAttributes.cs
- DesignerActionItemCollection.cs
- CustomWebEventKey.cs
- PkcsMisc.cs
- ReferenceConverter.cs
- RoleGroupCollection.cs
- NumericUpDownAcceleration.cs
- MatrixValueSerializer.cs
- hresults.cs
- GradientStopCollection.cs
- _SafeNetHandles.cs
- BamlLocalizationDictionary.cs
- XPathEmptyIterator.cs
- XamlLoadErrorInfo.cs
- ListItemParagraph.cs
- Padding.cs
- Debug.cs
- XmlSerializerFactory.cs
- SHA1CryptoServiceProvider.cs
- XmlReflectionImporter.cs
- XmlNamespaceDeclarationsAttribute.cs
- webproxy.cs
- KeyFrames.cs
- _HeaderInfoTable.cs
- BindingCollection.cs
- VectorAnimationBase.cs
- ConstrainedDataObject.cs
- SemaphoreSlim.cs
- KeysConverter.cs
- AuthenticationService.cs
- BinaryParser.cs
- MarshalByValueComponent.cs
- BamlTreeNode.cs
- XmlSchemaObjectTable.cs
- StrokeNodeOperations2.cs
- ActivityCodeDomSerializer.cs
- ThicknessAnimation.cs
- ExplicitDiscriminatorMap.cs
- WebBrowsableAttribute.cs
- SessionStateUtil.cs
- ToolStripOverflowButton.cs
- WebPartCatalogAddVerb.cs
- RelatedView.cs
- Operand.cs
- QueryInterceptorAttribute.cs
- SvcMapFileLoader.cs
- XamlNamespaceHelper.cs
- LineMetrics.cs
- SystemResourceKey.cs
- FontStyle.cs
- EventSetter.cs
- ChildTable.cs
- UnaryExpression.cs
- NumberEdit.cs
- ReachDocumentPageSerializer.cs
- MergeEnumerator.cs
- HtmlHead.cs
- DataSvcMapFileSerializer.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- CodeExpressionRuleDeclaration.cs
- CookieHandler.cs
- BaseCodeDomTreeGenerator.cs
- HttpListenerException.cs
- DesignerLabelAdapter.cs
- DelimitedListTraceListener.cs
- SignedXml.cs
- ComboBoxItem.cs
- DragDeltaEventArgs.cs
- TrackingDataItem.cs
- XmlIgnoreAttribute.cs
- COM2PropertyBuilderUITypeEditor.cs
- MarginsConverter.cs
- PageBreakRecord.cs
- HandlerMappingMemo.cs
- ColumnMapCopier.cs
- SafeArrayRankMismatchException.cs
- WebServiceMethodData.cs
- HtmlInputButton.cs
- AppDomainInstanceProvider.cs
- _SslSessionsCache.cs
- DetailsViewDeletedEventArgs.cs
- Classification.cs
- NodeInfo.cs
- DbMetaDataFactory.cs
- WebPartEditorApplyVerb.cs