Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Client / System / Data / Services / Client / ReferenceEqualityComparer.cs / 1305376 / ReferenceEqualityComparer.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a class that can compare objects for reference equality. // //--------------------------------------------------------------------- //// #define NON_GENERIC_AVAILABLE #if ASTORIA_CLIENT namespace System.Data.Services.Client #else namespace System.Data.Services #endif { #region Namespaces. using System.Collections.Generic; using System.Diagnostics; using System.Linq.Expressions; using System.Text; using System.Collections; #endregion Namespaces. ///Equality comparer implementation that uses reference equality. internal class ReferenceEqualityComparer : IEqualityComparer { #region Private fields. #if NON_GENERIC_AVAILABLE ///Singleton instance (non-generic, as opposed to the one in ReferenceEqualityComparer<T>. private static ReferenceEqualityComparer nonGenericInstance; #endif #endregion Private fields. #region Constructors. ///Initializes a new protected ReferenceEqualityComparer() { } #endregion Constructors. #region Properties. ///instance. Determines whether two objects are the same. /// First object to compare. /// Second object to compare. ///true if both are the same; false otherwise. bool IEqualityComparer.Equals(object x, object y) { return object.ReferenceEquals(x, y); } ///Serves as hashing function for collections. /// Object to hash. ////// Hash code for the object; shouldn't change through the lifetime /// of int IEqualityComparer.GetHashCode(object obj) { if (obj == null) { return 0; } return obj.GetHashCode(); } #if NON_GENERIC_AVAILABLE ///. /// Singleton instance (non-generic, as opposed to the one in ReferenceEqualityComparer<T>. internal ReferenceEqualityComparer NonGenericInstance { get { if (nonGenericInstance == null) { ReferenceEqualityComparer comparer = new ReferenceEqualityComparer(); System.Threading.Interlocked.CompareExchange(ref nonGenericInstance, comparer, null); } return nonGenericInstance; } } #endif #endregion Properties. } ////// Use this class to compare objects by reference in collections such as /// dictionary or hashsets. /// ///Type of objects to compare. ////// Typically accesses statically as eg /// ReferenceEqualityComparer<Expression>.Instance. /// internal sealed class ReferenceEqualityComparer: ReferenceEqualityComparer, IEqualityComparer { #region Private fields. /// Single instance per 'T' for comparison. private static ReferenceEqualityComparerinstance; #endregion Private fields. #region Constructors. /// Initializes a new private ReferenceEqualityComparer() : base() { } #endregion Constructors. #region Properties. ///instance. Returns a singleton instance for this comparer type. internal static ReferenceEqualityComparerInstance { get { if (instance == null) { Debug.Assert(!typeof(T).IsValueType, "!typeof(T).IsValueType -- can't use reference equality in a meaningful way with value types"); ReferenceEqualityComparer newInstance = new ReferenceEqualityComparer (); System.Threading.Interlocked.CompareExchange(ref instance, newInstance, null); } return instance; } } #endregion Properties. #region Methods. /// Determines whether two objects are the same. /// First object to compare. /// Second object to compare. ///true if both are the same; false otherwise. public bool Equals(T x, T y) { return object.ReferenceEquals(x, y); } ///Serves as hashing function for collections. /// Object to hash. ////// Hash code for the object; shouldn't change through the lifetime /// of public int GetHashCode(T obj) { if (obj == null) { return 0; } return obj.GetHashCode(); } #endregion Methods. } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //. /// // Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a class that can compare objects for reference equality. // //--------------------------------------------------------------------- //// #define NON_GENERIC_AVAILABLE #if ASTORIA_CLIENT namespace System.Data.Services.Client #else namespace System.Data.Services #endif { #region Namespaces. using System.Collections.Generic; using System.Diagnostics; using System.Linq.Expressions; using System.Text; using System.Collections; #endregion Namespaces. ///Equality comparer implementation that uses reference equality. internal class ReferenceEqualityComparer : IEqualityComparer { #region Private fields. #if NON_GENERIC_AVAILABLE ///Singleton instance (non-generic, as opposed to the one in ReferenceEqualityComparer<T>. private static ReferenceEqualityComparer nonGenericInstance; #endif #endregion Private fields. #region Constructors. ///Initializes a new protected ReferenceEqualityComparer() { } #endregion Constructors. #region Properties. ///instance. Determines whether two objects are the same. /// First object to compare. /// Second object to compare. ///true if both are the same; false otherwise. bool IEqualityComparer.Equals(object x, object y) { return object.ReferenceEquals(x, y); } ///Serves as hashing function for collections. /// Object to hash. ////// Hash code for the object; shouldn't change through the lifetime /// of int IEqualityComparer.GetHashCode(object obj) { if (obj == null) { return 0; } return obj.GetHashCode(); } #if NON_GENERIC_AVAILABLE ///. /// Singleton instance (non-generic, as opposed to the one in ReferenceEqualityComparer<T>. internal ReferenceEqualityComparer NonGenericInstance { get { if (nonGenericInstance == null) { ReferenceEqualityComparer comparer = new ReferenceEqualityComparer(); System.Threading.Interlocked.CompareExchange(ref nonGenericInstance, comparer, null); } return nonGenericInstance; } } #endif #endregion Properties. } ////// Use this class to compare objects by reference in collections such as /// dictionary or hashsets. /// ///Type of objects to compare. ////// Typically accesses statically as eg /// ReferenceEqualityComparer<Expression>.Instance. /// internal sealed class ReferenceEqualityComparer: ReferenceEqualityComparer, IEqualityComparer { #region Private fields. /// Single instance per 'T' for comparison. private static ReferenceEqualityComparerinstance; #endregion Private fields. #region Constructors. /// Initializes a new private ReferenceEqualityComparer() : base() { } #endregion Constructors. #region Properties. ///instance. Returns a singleton instance for this comparer type. internal static ReferenceEqualityComparerInstance { get { if (instance == null) { Debug.Assert(!typeof(T).IsValueType, "!typeof(T).IsValueType -- can't use reference equality in a meaningful way with value types"); ReferenceEqualityComparer newInstance = new ReferenceEqualityComparer (); System.Threading.Interlocked.CompareExchange(ref instance, newInstance, null); } return instance; } } #endregion Properties. #region Methods. /// Determines whether two objects are the same. /// First object to compare. /// Second object to compare. ///true if both are the same; false otherwise. public bool Equals(T x, T y) { return object.ReferenceEquals(x, y); } ///Serves as hashing function for collections. /// Object to hash. ////// Hash code for the object; shouldn't change through the lifetime /// of public int GetHashCode(T obj) { if (obj == null) { return 0; } return obj.GetHashCode(); } #endregion Methods. } } // 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
- UnmanagedHandle.cs
- Win32SafeHandles.cs
- DesignerExtenders.cs
- SubMenuStyle.cs
- WebServiceEndpoint.cs
- IPPacketInformation.cs
- NetWebProxyFinder.cs
- UserPersonalizationStateInfo.cs
- FileLoadException.cs
- ProfileGroupSettings.cs
- WebConfigurationManager.cs
- OdbcConnection.cs
- EdmProviderManifest.cs
- NetTcpSecurityElement.cs
- IdentifierCreationService.cs
- EndpointConfigContainer.cs
- StoreAnnotationsMap.cs
- compensatingcollection.cs
- ApplicationTrust.cs
- IndexOutOfRangeException.cs
- WmlObjectListAdapter.cs
- CodeDefaultValueExpression.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- HtmlTable.cs
- MarshalDirectiveException.cs
- EncodingDataItem.cs
- ObjectToIdCache.cs
- FileUpload.cs
- HtmlTableCell.cs
- SessionSwitchEventArgs.cs
- NavigationPropertyEmitter.cs
- CacheOutputQuery.cs
- DataBindingHandlerAttribute.cs
- PeerNameRecordCollection.cs
- SplashScreen.cs
- ParagraphVisual.cs
- PriorityRange.cs
- StubHelpers.cs
- EnumerableRowCollectionExtensions.cs
- QuotaThrottle.cs
- selecteditemcollection.cs
- PrefixQName.cs
- GeneratedContractType.cs
- DataControlLinkButton.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- XXXInfos.cs
- TemplatePropertyEntry.cs
- SynchronizationLockException.cs
- HtmlElementErrorEventArgs.cs
- ListManagerBindingsCollection.cs
- figurelength.cs
- XmlRawWriterWrapper.cs
- ExpressionSelection.cs
- _LocalDataStoreMgr.cs
- DynamicDocumentPaginator.cs
- InputScopeNameConverter.cs
- HebrewCalendar.cs
- OleDbPermission.cs
- TagPrefixInfo.cs
- serverconfig.cs
- WizardStepBase.cs
- ZoneButton.cs
- DispatcherExceptionFilterEventArgs.cs
- EastAsianLunisolarCalendar.cs
- SimpleTextLine.cs
- ScopelessEnumAttribute.cs
- processwaithandle.cs
- LambdaReference.cs
- DataGridSortingEventArgs.cs
- KoreanLunisolarCalendar.cs
- DESCryptoServiceProvider.cs
- ExpressionBuilderCollection.cs
- HasRunnableWorkflowEvent.cs
- Separator.cs
- ParallelQuery.cs
- Events.cs
- ObjectAssociationEndMapping.cs
- COM2ExtendedBrowsingHandler.cs
- TemplatedControlDesigner.cs
- Column.cs
- XPathDocumentIterator.cs
- XmlSchemaIdentityConstraint.cs
- TypeDescriptionProvider.cs
- WindowsContainer.cs
- ChannelSinkStacks.cs
- ByteAnimationUsingKeyFrames.cs
- SecurityPermission.cs
- ApplicationTrust.cs
- DateTimeValueSerializer.cs
- MenuItemStyle.cs
- SourceItem.cs
- Journal.cs
- RequestCachePolicy.cs
- XsltOutput.cs
- Domain.cs
- DebuggerService.cs
- ClientTargetCollection.cs
- WindowsSysHeader.cs
- Encoder.cs
- AstTree.cs