Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- IndexerNameAttribute.cs
- RelatedCurrencyManager.cs
- ComAwareEventInfo.cs
- StreamGeometryContext.cs
- TemplateControlBuildProvider.cs
- MaterialCollection.cs
- SystemIPInterfaceStatistics.cs
- GraphicsContext.cs
- UrlAuthFailedErrorFormatter.cs
- FixedTextView.cs
- PackageStore.cs
- CollectionConverter.cs
- Formatter.cs
- SQLInt32Storage.cs
- ForeignConstraint.cs
- DbUpdateCommandTree.cs
- ThicknessConverter.cs
- ToolboxItemCollection.cs
- RSAOAEPKeyExchangeFormatter.cs
- FixedSOMPage.cs
- TemplatedMailWebEventProvider.cs
- ObjectDataSourceFilteringEventArgs.cs
- BinaryUtilClasses.cs
- TextDocumentView.cs
- DtdParser.cs
- Point3DKeyFrameCollection.cs
- SqlClientFactory.cs
- WebPartConnectionsDisconnectVerb.cs
- WebPartConnectVerb.cs
- GlobalProxySelection.cs
- UIElement3DAutomationPeer.cs
- TrimSurroundingWhitespaceAttribute.cs
- ObjectStateFormatter.cs
- RedistVersionInfo.cs
- AssociativeAggregationOperator.cs
- CriticalFinalizerObject.cs
- SrgsRulesCollection.cs
- WmlListAdapter.cs
- FormViewPagerRow.cs
- DescriptionAttribute.cs
- TypeToTreeConverter.cs
- DefaultProxySection.cs
- FrameSecurityDescriptor.cs
- RelOps.cs
- DefaultBinder.cs
- DataGridViewCellPaintingEventArgs.cs
- JpegBitmapDecoder.cs
- UrlAuthorizationModule.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- TextBoxRenderer.cs
- InteropBitmapSource.cs
- BindingList.cs
- ClassDataContract.cs
- HttpProfileBase.cs
- ClientSideProviderDescription.cs
- TextRangeBase.cs
- WindowsProgressbar.cs
- COM2Properties.cs
- FileDialogCustomPlacesCollection.cs
- LocationSectionRecord.cs
- ActivationServices.cs
- MailDefinition.cs
- IUnknownConstantAttribute.cs
- BaseValidator.cs
- ClickablePoint.cs
- SecurityToken.cs
- MergeExecutor.cs
- HtmlMeta.cs
- SymmetricKey.cs
- ManualResetEvent.cs
- ClientRolePrincipal.cs
- Property.cs
- TypeConverter.cs
- ChildTable.cs
- PageStatePersister.cs
- LoginCancelEventArgs.cs
- ApplicationException.cs
- EncoderFallback.cs
- PrintPreviewGraphics.cs
- WebBrowserNavigatingEventHandler.cs
- RemotingException.cs
- ConnectionManagementElementCollection.cs
- HMACSHA512.cs
- DirtyTextRange.cs
- ArrayTypeMismatchException.cs
- ManualResetEvent.cs
- Base64Decoder.cs
- ImageMetadata.cs
- ColorKeyFrameCollection.cs
- WebProxyScriptElement.cs
- DataSourceXmlSerializer.cs
- DoubleCollection.cs
- GiveFeedbackEvent.cs
- BaseTemplateCodeDomTreeGenerator.cs
- TextUtf8RawTextWriter.cs
- ResourceReferenceExpression.cs
- WorkflowMarkupSerializerMapping.cs
- GridLength.cs
- CookieHandler.cs
- EditorZone.cs