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
- ScrollContentPresenter.cs
- XmlQualifiedNameTest.cs
- PrintDialog.cs
- MarkerProperties.cs
- MappedMetaModel.cs
- PartialCachingControl.cs
- Publisher.cs
- FixedSOMPageConstructor.cs
- PropertyBuilder.cs
- SqlUDTStorage.cs
- GradientStopCollection.cs
- XslAst.cs
- IPipelineRuntime.cs
- StylusPointDescription.cs
- SerializationObjectManager.cs
- XmlSerializerAssemblyAttribute.cs
- FrameworkElementFactoryMarkupObject.cs
- Wizard.cs
- XomlCompilerHelpers.cs
- DesignerVerbCollection.cs
- ValidatedControlConverter.cs
- Glyph.cs
- XmlAttributeCache.cs
- dataprotectionpermissionattribute.cs
- QueryContinueDragEvent.cs
- MemoryRecordBuffer.cs
- StateDesigner.CommentLayoutGlyph.cs
- SiteMapPath.cs
- SetIterators.cs
- HostedImpersonationContext.cs
- RequestCache.cs
- FormsAuthenticationTicket.cs
- AuthorizationRuleCollection.cs
- IndentedWriter.cs
- XmlRawWriterWrapper.cs
- TypeInfo.cs
- DocumentApplicationJournalEntry.cs
- IsolatedStorage.cs
- RightsManagementInformation.cs
- TableLayoutStyle.cs
- AttributeCollection.cs
- SqlFacetAttribute.cs
- MarkupCompilePass1.cs
- DebugView.cs
- ISCIIEncoding.cs
- AtomServiceDocumentSerializer.cs
- EditorZoneBase.cs
- MessageFilter.cs
- MailAddress.cs
- ToolStripContextMenu.cs
- _UriTypeConverter.cs
- DBConnection.cs
- ProfileService.cs
- TextSchema.cs
- FamilyMapCollection.cs
- ExtendedPropertyDescriptor.cs
- SerializerWriterEventHandlers.cs
- ProcessInputEventArgs.cs
- SerTrace.cs
- TrustManagerMoreInformation.cs
- StringExpressionSet.cs
- EntityDataSourceConfigureObjectContextPanel.cs
- GlobalizationAssembly.cs
- ListView.cs
- SqlCacheDependencySection.cs
- ToolStripSplitButton.cs
- ServiceProviders.cs
- TemplateKeyConverter.cs
- CustomPopupPlacement.cs
- CheckBoxBaseAdapter.cs
- CollectionView.cs
- EffectiveValueEntry.cs
- DbMetaDataCollectionNames.cs
- ProcessModule.cs
- WebHttpBindingElement.cs
- StorageFunctionMapping.cs
- DefaultPropertyAttribute.cs
- LocationReferenceValue.cs
- UniformGrid.cs
- ModuleBuilderData.cs
- Operators.cs
- ServiceContractListItem.cs
- TableCellAutomationPeer.cs
- StrokeNodeOperations.cs
- GridViewSelectEventArgs.cs
- SweepDirectionValidation.cs
- NativeMethods.cs
- SerialPort.cs
- SqlStatistics.cs
- WorkflowOperationBehavior.cs
- DoubleMinMaxAggregationOperator.cs
- ComponentCommands.cs
- RepeaterCommandEventArgs.cs
- GeometryValueSerializer.cs
- CheckBoxAutomationPeer.cs
- FlowLayout.cs
- DataGridColumnCollection.cs
- ListViewPagedDataSource.cs
- GenericUriParser.cs
- ListMarkerLine.cs