Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Collections / Comparer.cs / 1 / 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;
[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");
}
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"));
}
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
public void GetObjectData(SerializationInfo info, StreamingContext context) {
if (info==null) {
throw new ArgumentNullException("info");
}
if( m_compareInfo != null) {
info.AddValue(CompareInfoName, m_compareInfo);
}
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ProfileProvider.cs
- MarginCollapsingState.cs
- ThreadPool.cs
- JavascriptCallbackMessageInspector.cs
- StringPropertyBuilder.cs
- DrawingVisual.cs
- WebPartConnectionsConnectVerb.cs
- SignedXml.cs
- XPathAxisIterator.cs
- QilNode.cs
- XamlTemplateSerializer.cs
- PersonalizableTypeEntry.cs
- InternalDispatchObject.cs
- WebConfigurationFileMap.cs
- ToolStripCodeDomSerializer.cs
- HttpCapabilitiesEvaluator.cs
- AsmxEndpointPickerExtension.cs
- WindowsSysHeader.cs
- SqlDeflator.cs
- PrimaryKeyTypeConverter.cs
- TransactionManager.cs
- NullRuntimeConfig.cs
- ProfileElement.cs
- SemanticTag.cs
- RoutedEventConverter.cs
- SendingRequestEventArgs.cs
- ZipIOFileItemStream.cs
- HandoffBehavior.cs
- DataGridHelper.cs
- SqlVisitor.cs
- ButtonRenderer.cs
- DataGridViewCellFormattingEventArgs.cs
- SignatureConfirmations.cs
- querybuilder.cs
- __Filters.cs
- ListViewInsertEventArgs.cs
- HealthMonitoringSectionHelper.cs
- DesignerSerializationVisibilityAttribute.cs
- XmlArrayItemAttribute.cs
- MethodToken.cs
- ToolStripDropDownClosedEventArgs.cs
- InstanceLockedException.cs
- FormViewUpdatedEventArgs.cs
- CryptoStream.cs
- CompilerError.cs
- ComponentDispatcher.cs
- OpenFileDialog.cs
- TransformProviderWrapper.cs
- RawKeyboardInputReport.cs
- InputLanguageCollection.cs
- StatusBarPanel.cs
- TemplatedWizardStep.cs
- MsmqIntegrationOutputChannel.cs
- ArrangedElement.cs
- ZipIOModeEnforcingStream.cs
- PackagePartCollection.cs
- DataListItem.cs
- SafeProcessHandle.cs
- ElementUtil.cs
- ActivityTypeCodeDomSerializer.cs
- ConnectionOrientedTransportBindingElement.cs
- hresults.cs
- WindowsListViewSubItem.cs
- NamedPipeActivation.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- DefaultSerializationProviderAttribute.cs
- ManagementOptions.cs
- ExtentKey.cs
- BamlBinaryWriter.cs
- ModelItemCollection.cs
- HttpPostProtocolImporter.cs
- HttpModuleAction.cs
- GeneralTransform3DTo2DTo3D.cs
- LogLogRecord.cs
- Exceptions.cs
- InternalMappingException.cs
- DiscoveryDocumentReference.cs
- ScriptResourceAttribute.cs
- CommentEmitter.cs
- DataServices.cs
- NumericUpDownAccelerationCollection.cs
- HMACSHA1.cs
- ObjectDataSourceFilteringEventArgs.cs
- ColorBlend.cs
- XmlSubtreeReader.cs
- FullTrustAssembliesSection.cs
- StructuredTypeInfo.cs
- PictureBox.cs
- MenuItemStyle.cs
- SafeNativeMethods.cs
- WorkflowLayouts.cs
- ExeConfigurationFileMap.cs
- UnauthorizedAccessException.cs
- RuleRefElement.cs
- MasterPage.cs
- ContainerParaClient.cs
- CustomBindingCollectionElement.cs
- RegularExpressionValidator.cs
- IntersectQueryOperator.cs
- ProfileSettings.cs