Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Collections / Comparer.cs / 1305376 / Comparer.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: Comparer ** **[....] ** ** ** Purpose: Default IComparer implementation. ** ** ===========================================================*/ namespace System.Collections { using System; using System.Globalization; using System.Runtime.Serialization; using System.Security.Permissions; using System.Diagnostics.Contracts; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Comparer : IComparer , ISerializable { private CompareInfo m_compareInfo; public static readonly Comparer Default = new Comparer(CultureInfo.CurrentCulture); public static readonly Comparer DefaultInvariant = new Comparer(CultureInfo.InvariantCulture); private const String CompareInfoName = "CompareInfo"; private Comparer() { m_compareInfo = null; } public Comparer(CultureInfo culture) { if (culture==null) { throw new ArgumentNullException("culture"); } Contract.EndContractBlock(); m_compareInfo = culture.CompareInfo; } private Comparer(SerializationInfo info, StreamingContext context) { m_compareInfo = null; SerializationInfoEnumerator enumerator = info.GetEnumerator(); while( enumerator.MoveNext()) { switch( enumerator.Name) { case CompareInfoName: m_compareInfo = (CompareInfo) info.GetValue(CompareInfoName, typeof(CompareInfo)); break; } } } // Compares two Objects by calling CompareTo. If a == // b,0 is returned. If a implements // IComparable, a.CompareTo(b) is returned. If a // doesn't implement IComparable and b does, // -(b.CompareTo(a)) is returned, otherwise an // exception is thrown. // public int Compare(Object a, Object b) { if (a == b) return 0; if (a == null) return -1; if (b == null) return 1; if (m_compareInfo != null) { String sa = a as String; String sb = b as String; if (sa != null && sb != null) return m_compareInfo.Compare(sa, sb); } IComparable ia = a as IComparable; if (ia != null) return ia.CompareTo(b); throw new ArgumentException(Environment.GetResourceString("Argument_ImplementIComparable")); } [System.Security.SecurityCritical] // auto-generated_required public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { throw new ArgumentNullException("info"); } Contract.EndContractBlock(); if( m_compareInfo != null) { info.AddValue(CompareInfoName, m_compareInfo); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: Comparer ** **[....] ** ** ** Purpose: Default IComparer implementation. ** ** ===========================================================*/ namespace System.Collections { using System; using System.Globalization; using System.Runtime.Serialization; using System.Security.Permissions; using System.Diagnostics.Contracts; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Comparer : IComparer , ISerializable { private CompareInfo m_compareInfo; public static readonly Comparer Default = new Comparer(CultureInfo.CurrentCulture); public static readonly Comparer DefaultInvariant = new Comparer(CultureInfo.InvariantCulture); private const String CompareInfoName = "CompareInfo"; private Comparer() { m_compareInfo = null; } public Comparer(CultureInfo culture) { if (culture==null) { throw new ArgumentNullException("culture"); } Contract.EndContractBlock(); m_compareInfo = culture.CompareInfo; } private Comparer(SerializationInfo info, StreamingContext context) { m_compareInfo = null; SerializationInfoEnumerator enumerator = info.GetEnumerator(); while( enumerator.MoveNext()) { switch( enumerator.Name) { case CompareInfoName: m_compareInfo = (CompareInfo) info.GetValue(CompareInfoName, typeof(CompareInfo)); break; } } } // Compares two Objects by calling CompareTo. If a == // b,0 is returned. If a implements // IComparable, a.CompareTo(b) is returned. If a // doesn't implement IComparable and b does, // -(b.CompareTo(a)) is returned, otherwise an // exception is thrown. // public int Compare(Object a, Object b) { if (a == b) return 0; if (a == null) return -1; if (b == null) return 1; if (m_compareInfo != null) { String sa = a as String; String sb = b as String; if (sa != null && sb != null) return m_compareInfo.Compare(sa, sb); } IComparable ia = a as IComparable; if (ia != null) return ia.CompareTo(b); throw new ArgumentException(Environment.GetResourceString("Argument_ImplementIComparable")); } [System.Security.SecurityCritical] // auto-generated_required public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { throw new ArgumentNullException("info"); } Contract.EndContractBlock(); if( m_compareInfo != null) { info.AddValue(CompareInfoName, m_compareInfo); } } } } // 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
- HtmlCommandAdapter.cs
- ProjectionPathSegment.cs
- CompressStream.cs
- CurrentChangingEventArgs.cs
- IFormattable.cs
- StructuredType.cs
- HandlerFactoryWrapper.cs
- TextServicesHost.cs
- ModulesEntry.cs
- PrintDialog.cs
- EventKeyword.cs
- ErrorEventArgs.cs
- IgnoreFileBuildProvider.cs
- ExpandoObject.cs
- PrivilegedConfigurationManager.cs
- RemoteWebConfigurationHostStream.cs
- MessageLoggingElement.cs
- DiscoveryDocument.cs
- SourceFilter.cs
- JournalEntry.cs
- IfElseDesigner.xaml.cs
- GroupJoinQueryOperator.cs
- GPPOINT.cs
- Light.cs
- OpenFileDialog.cs
- EntityWithChangeTrackerStrategy.cs
- CounterSampleCalculator.cs
- SmiTypedGetterSetter.cs
- SqlDependencyListener.cs
- InputReport.cs
- PassportAuthentication.cs
- OutputCacheSettingsSection.cs
- XPathCompileException.cs
- BindingMAnagerBase.cs
- GlobalizationSection.cs
- DllNotFoundException.cs
- XamlTypeMapper.cs
- MenuTracker.cs
- Int16.cs
- CFStream.cs
- FullTextBreakpoint.cs
- DnsElement.cs
- CacheManager.cs
- PasswordPropertyTextAttribute.cs
- Debug.cs
- WebResourceAttribute.cs
- TypeValidationEventArgs.cs
- CanonicalFormWriter.cs
- SystemUdpStatistics.cs
- ColorAnimationUsingKeyFrames.cs
- DataKeyArray.cs
- PieceNameHelper.cs
- ColumnResizeUndoUnit.cs
- PathNode.cs
- ProfileGroupSettingsCollection.cs
- LambdaSerializationException.cs
- DesignOnlyAttribute.cs
- QilList.cs
- SqlDataSourceFilteringEventArgs.cs
- SQLString.cs
- ListViewGroupItemCollection.cs
- WorkItem.cs
- InternalBufferOverflowException.cs
- CustomTrackingRecord.cs
- ViewStateException.cs
- WebPartDescription.cs
- WebPartHelpVerb.cs
- FamilyCollection.cs
- DBSchemaRow.cs
- MultilineStringEditor.cs
- IsolatedStorageException.cs
- TrackingMemoryStream.cs
- DifferencingCollection.cs
- DBNull.cs
- Parser.cs
- Polygon.cs
- WebPartManager.cs
- DetailsViewUpdateEventArgs.cs
- PlaceHolder.cs
- Size.cs
- SplayTreeNode.cs
- NavigationFailedEventArgs.cs
- ComplexPropertyEntry.cs
- TextDecorations.cs
- Resources.Designer.cs
- EntityWrapper.cs
- SelectedCellsCollection.cs
- ColorKeyFrameCollection.cs
- MediaEntryAttribute.cs
- XmlSerializationWriter.cs
- ReferenceService.cs
- AdjustableArrowCap.cs
- DateTimeParse.cs
- VScrollProperties.cs
- ModelEditingScope.cs
- SimpleTextLine.cs
- RTTrackingProfile.cs
- CollaborationHelperFunctions.cs
- KeyValueInternalCollection.cs
- MimeAnyImporter.cs