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 instance.
protected ReferenceEqualityComparer()
{
}
#endregion Constructors.
#region Properties.
/// 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 ReferenceEqualityComparer instance;
#endregion Private fields.
#region Constructors.
/// Initializes a new instance.
private ReferenceEqualityComparer() : base()
{
}
#endregion Constructors.
#region Properties.
/// Returns a singleton instance for this comparer type.
internal static ReferenceEqualityComparer Instance
{
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 instance.
protected ReferenceEqualityComparer()
{
}
#endregion Constructors.
#region Properties.
/// 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 ReferenceEqualityComparer instance;
#endregion Private fields.
#region Constructors.
/// Initializes a new instance.
private ReferenceEqualityComparer() : base()
{
}
#endregion Constructors.
#region Properties.
/// Returns a singleton instance for this comparer type.
internal static ReferenceEqualityComparer Instance
{
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
- TableParagraph.cs
- XmlArrayItemAttribute.cs
- Convert.cs
- QilReplaceVisitor.cs
- HtmlImage.cs
- RequestSecurityTokenForGetBrowserToken.cs
- MethodImplAttribute.cs
- ExpressionBuilder.cs
- RecognitionResult.cs
- SqlFactory.cs
- AccessViolationException.cs
- XmlDataDocument.cs
- CapacityStreamGeometryContext.cs
- FixedSOMTableRow.cs
- MenuRendererStandards.cs
- ConstraintEnumerator.cs
- VerificationAttribute.cs
- WS2007FederationHttpBinding.cs
- EmptyElement.cs
- EventPropertyMap.cs
- TextTreePropertyUndoUnit.cs
- SchemaTableOptionalColumn.cs
- StyleCollectionEditor.cs
- FormViewDeleteEventArgs.cs
- ComponentDesigner.cs
- TreeIterator.cs
- HMACRIPEMD160.cs
- WinCategoryAttribute.cs
- exports.cs
- HideDisabledControlAdapter.cs
- OleDbError.cs
- ErrorStyle.cs
- StringAnimationUsingKeyFrames.cs
- WriteableOnDemandPackagePart.cs
- HtmlInputControl.cs
- FrugalMap.cs
- SiteIdentityPermission.cs
- ElementMarkupObject.cs
- InvalidStoreProtectionKeyException.cs
- TablePatternIdentifiers.cs
- DataSetUtil.cs
- StringExpressionSet.cs
- IgnoreSectionHandler.cs
- PolygonHotSpot.cs
- SecurityDescriptor.cs
- TranslateTransform3D.cs
- FormatSettings.cs
- ConnectionInterfaceCollection.cs
- SchemaElement.cs
- IPHostEntry.cs
- UdpTransportBindingElement.cs
- SQLMoneyStorage.cs
- SchemaAttDef.cs
- CodeGen.cs
- COM2Enum.cs
- cookiecontainer.cs
- ToolStripSystemRenderer.cs
- EntityUtil.cs
- NavigationService.cs
- FillBehavior.cs
- Pkcs7Recipient.cs
- TokenBasedSetEnumerator.cs
- PermissionRequestEvidence.cs
- JoinGraph.cs
- BrowsableAttribute.cs
- Win32PrintDialog.cs
- TCEAdapterGenerator.cs
- LoginCancelEventArgs.cs
- ItemList.cs
- SpecialFolderEnumConverter.cs
- EventBuilder.cs
- Floater.cs
- SharedRuntimeState.cs
- ScriptingWebServicesSectionGroup.cs
- PersistenceTypeAttribute.cs
- Symbol.cs
- WebPartHeaderCloseVerb.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- XPathSingletonIterator.cs
- DataControlLinkButton.cs
- Popup.cs
- HatchBrush.cs
- ListViewGroupItemCollection.cs
- SqlUserDefinedAggregateAttribute.cs
- BitmapEffectDrawingContextWalker.cs
- XmlSecureResolver.cs
- NamedPipeConnectionPoolSettings.cs
- ErrorTableItemStyle.cs
- DbSource.cs
- ImmutableAssemblyCacheEntry.cs
- IPEndPointCollection.cs
- StateManagedCollection.cs
- DefaultPropertiesToSend.cs
- EntityDataSourceDesignerHelper.cs
- SerializerDescriptor.cs
- OdbcConnectionFactory.cs
- TraceContextEventArgs.cs
- RootBrowserWindowProxy.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- StringComparer.cs