Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Common / Utils / CdpEqualityComparer.cs / 1 / CdpEqualityComparer.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Text; using System.Globalization; using System.Data.SqlTypes; using System.Diagnostics; namespace System.Data.Common.Utils { ////// Equality comparer implementation that uses case-sensitive ordinal comparison for strings. /// internal sealed class CdpEqualityComparer : IEqualityComparer { ////// Private constructor to ensure comparer is only accessed through the private CdpEqualityComparer() { } private static readonly IEqualityComparer s_defaultEqualityComparer = new CdpEqualityComparer(); ////// property. /// /// Gets instance of CdpEqualityComparer. /// static internal IEqualityComparer DefaultEqualityComparer { get { return s_defaultEqualityComparer; } } ////// This mirrors the .NET implementation of System.Collections.Comparer but /// uses an ordinal comparer for strings rather than a linguistic compare. /// /// First object to compare /// Second object to compare ///True if the arguments are equivalent; false otherwise bool IEqualityComparer.Equals(object x, object y) { // if the objects are equal by reference, return immediately if (x == y) { return true; } // if either one or the other objects is null, return false // (they cannot both be null, because otherwise the reference equality check // would have succeeded) if (null == x || null == y) { return false; } // if we're dealing with strings, special handling is required string xAsString = x as string; if (null != xAsString) { string yAsString = y as string; if (null != yAsString) { return StringComparer.Ordinal.Equals(xAsString, yAsString); } else { // string implements IComparable, so we can avoid a second cast return 0 == xAsString.CompareTo(y); } } // use first argument as IComparable IComparable xAsComparable = x as IComparable; if (null != xAsComparable) { return 0 == xAsComparable.CompareTo(y); } else { // default to Equals implementation return x.Equals(y); } } ////// Retursn hash code for given object. /// /// Object for which to produce hash code (throws if null) ///Hash code for argument int IEqualityComparer.GetHashCode(object obj) { Debug.Assert(null != obj); return obj.GetHashCode(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Text; using System.Globalization; using System.Data.SqlTypes; using System.Diagnostics; namespace System.Data.Common.Utils { ////// Equality comparer implementation that uses case-sensitive ordinal comparison for strings. /// internal sealed class CdpEqualityComparer : IEqualityComparer { ////// Private constructor to ensure comparer is only accessed through the private CdpEqualityComparer() { } private static readonly IEqualityComparer s_defaultEqualityComparer = new CdpEqualityComparer(); ////// property. /// /// Gets instance of CdpEqualityComparer. /// static internal IEqualityComparer DefaultEqualityComparer { get { return s_defaultEqualityComparer; } } ////// This mirrors the .NET implementation of System.Collections.Comparer but /// uses an ordinal comparer for strings rather than a linguistic compare. /// /// First object to compare /// Second object to compare ///True if the arguments are equivalent; false otherwise bool IEqualityComparer.Equals(object x, object y) { // if the objects are equal by reference, return immediately if (x == y) { return true; } // if either one or the other objects is null, return false // (they cannot both be null, because otherwise the reference equality check // would have succeeded) if (null == x || null == y) { return false; } // if we're dealing with strings, special handling is required string xAsString = x as string; if (null != xAsString) { string yAsString = y as string; if (null != yAsString) { return StringComparer.Ordinal.Equals(xAsString, yAsString); } else { // string implements IComparable, so we can avoid a second cast return 0 == xAsString.CompareTo(y); } } // use first argument as IComparable IComparable xAsComparable = x as IComparable; if (null != xAsComparable) { return 0 == xAsComparable.CompareTo(y); } else { // default to Equals implementation return x.Equals(y); } } ////// Retursn hash code for given object. /// /// Object for which to produce hash code (throws if null) ///Hash code for argument int IEqualityComparer.GetHashCode(object obj) { Debug.Assert(null != obj); return obj.GetHashCode(); } } } // 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
- PinnedBufferMemoryStream.cs
- TimeStampChecker.cs
- EndOfStreamException.cs
- FontCacheUtil.cs
- FontSizeConverter.cs
- BindingRestrictions.cs
- MonitoringDescriptionAttribute.cs
- ProtocolsConfiguration.cs
- QilPatternVisitor.cs
- StatusBarItemAutomationPeer.cs
- TypeUsage.cs
- BaseInfoTable.cs
- TrackBar.cs
- PointConverter.cs
- StringArrayConverter.cs
- SecurityTokenProvider.cs
- WindowsGraphics.cs
- GridViewRowPresenterBase.cs
- BrowserCapabilitiesFactory35.cs
- X509Chain.cs
- InstanceData.cs
- ToolStripScrollButton.cs
- WeakEventTable.cs
- FormViewUpdatedEventArgs.cs
- NativeMethods.cs
- NeutralResourcesLanguageAttribute.cs
- Hyperlink.cs
- FormViewAutoFormat.cs
- ISFTagAndGuidCache.cs
- Relationship.cs
- InvokePattern.cs
- DbConnectionStringCommon.cs
- Permission.cs
- OrderedDictionary.cs
- DoubleConverter.cs
- CharacterBufferReference.cs
- NumberSubstitution.cs
- AspNetCompatibilityRequirementsMode.cs
- Bold.cs
- SelectorItemAutomationPeer.cs
- SR.Designer.cs
- ProvidePropertyAttribute.cs
- RegistryPermission.cs
- OdbcConnectionString.cs
- Metafile.cs
- XmlQueryTypeFactory.cs
- storagemappingitemcollection.viewdictionary.cs
- SafeLocalAllocation.cs
- ObfuscationAttribute.cs
- XmlExpressionDumper.cs
- CredentialCache.cs
- WebPartMovingEventArgs.cs
- XmlSerializerSection.cs
- UnsafePeerToPeerMethods.cs
- SvcMapFileLoader.cs
- DataKey.cs
- MeshGeometry3D.cs
- CodeConstructor.cs
- CodeSnippetTypeMember.cs
- SystemIcmpV6Statistics.cs
- NativeMethods.cs
- BasicHttpMessageCredentialType.cs
- AnnouncementInnerClientCD1.cs
- XmlLinkedNode.cs
- NumberSubstitution.cs
- ExcludePathInfo.cs
- Executor.cs
- Substitution.cs
- SafePointer.cs
- XsdDateTime.cs
- ProtocolsConfiguration.cs
- CodeDomSerializerException.cs
- DataGridTextBoxColumn.cs
- SqlBulkCopyColumnMapping.cs
- NameValueConfigurationElement.cs
- ErasingStroke.cs
- RequestQueue.cs
- ProviderSettingsCollection.cs
- BrowserInteropHelper.cs
- LoginUtil.cs
- Viewport3DVisual.cs
- WindowPattern.cs
- GeneralTransform3DTo2D.cs
- OperationInvokerTrace.cs
- OverlappedAsyncResult.cs
- ObjectConverter.cs
- Merger.cs
- ResetableIterator.cs
- CopyOfAction.cs
- LinearKeyFrames.cs
- PolicyException.cs
- _BufferOffsetSize.cs
- ChooseAction.cs
- Blend.cs
- DataGridColumnStyleMappingNameEditor.cs
- WorkflowRuntimeEndpoint.cs
- StateMachine.cs
- _HeaderInfoTable.cs
- RectangleGeometry.cs
- CodeTypeReferenceCollection.cs