Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- ValueSerializer.cs
- WebBrowser.cs
- AutomationPattern.cs
- Win32SafeHandles.cs
- AddInController.cs
- MobileResource.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- Walker.cs
- TextBox.cs
- Light.cs
- XmlChoiceIdentifierAttribute.cs
- ActivityValidationServices.cs
- CodeDomConfigurationHandler.cs
- ProcessStartInfo.cs
- JulianCalendar.cs
- Comparer.cs
- SmiTypedGetterSetter.cs
- WmlTextBoxAdapter.cs
- BrushConverter.cs
- TextTreeUndoUnit.cs
- HttpRuntime.cs
- mediaclock.cs
- QualifiedCellIdBoolean.cs
- ZipFileInfo.cs
- OutputScopeManager.cs
- _CommandStream.cs
- RichTextBoxConstants.cs
- StylusPoint.cs
- DefaultBindingPropertyAttribute.cs
- _TimerThread.cs
- TableHeaderCell.cs
- ColumnResult.cs
- EmptyQuery.cs
- WebPartZoneBase.cs
- SQlBooleanStorage.cs
- XmlEnumAttribute.cs
- ButtonPopupAdapter.cs
- AutomationIdentifier.cs
- VersionPair.cs
- DropSource.cs
- QilUnary.cs
- GCHandleCookieTable.cs
- CompModHelpers.cs
- DriveInfo.cs
- documentsequencetextcontainer.cs
- ZipIOBlockManager.cs
- ImageUrlEditor.cs
- EventEntry.cs
- Cursors.cs
- ButtonFlatAdapter.cs
- CompensateDesigner.cs
- FileNotFoundException.cs
- XPathNodePointer.cs
- DivideByZeroException.cs
- DataGridViewBindingCompleteEventArgs.cs
- TriggerBase.cs
- TempFiles.cs
- Authorization.cs
- QilUnary.cs
- EntityDataSourceContextCreatingEventArgs.cs
- GroupQuery.cs
- DisplayInformation.cs
- NetworkAddressChange.cs
- TagPrefixCollection.cs
- TextPattern.cs
- ContractListAdapter.cs
- CodeArrayIndexerExpression.cs
- BaseComponentEditor.cs
- ELinqQueryState.cs
- MsmqException.cs
- SQLStringStorage.cs
- MemoryRecordBuffer.cs
- _LocalDataStoreMgr.cs
- DrawingContextDrawingContextWalker.cs
- PrintingPermissionAttribute.cs
- NetworkInformationPermission.cs
- SectionVisual.cs
- dataSvcMapFileLoader.cs
- ParentUndoUnit.cs
- GridViewHeaderRowPresenter.cs
- AttachedAnnotationChangedEventArgs.cs
- GeometryGroup.cs
- HtmlTableRow.cs
- WebPartTransformer.cs
- ReaderContextStackData.cs
- BindableTemplateBuilder.cs
- SyntaxCheck.cs
- LightweightCodeGenerator.cs
- NTAccount.cs
- ReadOnlyDataSourceView.cs
- TraceRecord.cs
- ContentDisposition.cs
- XmlDataSourceView.cs
- ChangeToolStripParentVerb.cs
- BoundField.cs
- WebUtil.cs
- SwitchAttribute.cs
- XmlException.cs
- DataGridHeaderBorder.cs
- _TLSstream.cs