XmlNodeComparer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Data / XmlNodeComparer.cs / 1305600 / XmlNodeComparer.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// Description: Defines XmlNodeComparer object, used to sort a view of data produced by an XmlDataSource. 
// 
// Specs:       http://avalon/connecteddata/M5%20Specs/UIBinding.mht
// 
//---------------------------------------------------------------------------

using System;
using System.Collections; 
using System.Collections.Generic;
using System.ComponentModel; 
using System.Globalization; 

using System.Xml; 
using MS.Internal.Data;

namespace MS.Internal.Data
{ 
    /// 
    /// The XmlNodeComparer is used to sort a view of data produced by an XmlDataSource. 
    ///  
    internal class XmlNodeComparer : IComparer
    { 
        /// 
        /// Constructor.
        /// 
        ///  array of sort parameters  
        ///  namespace manager, to control queries
        /// culture to use for comparisons 
        internal XmlNodeComparer(SortDescriptionCollection sortParameters, XmlNamespaceManager namespaceManager, CultureInfo culture) 
        {
            _sortParameters = sortParameters; 
            _namespaceManager = namespaceManager;
            _culture = (culture == null) ? CultureInfo.InvariantCulture : culture;
        }
 
        int IComparer.Compare(object o1, object o2)
        { 
            int result = 0; 
            XmlNode node1 = o1 as XmlNode;
            XmlNode node2 = o2 as XmlNode; 

            if (node1 == null)
                return -1;
            if (node2 == null) 
                return +1;
 
            for (int k = 0; k < _sortParameters.Count; ++k) 
            {
                string valueX = AssemblyHelper.SelectStringValue(node1, _sortParameters[k].PropertyName, _namespaceManager); 
                string valueY = AssemblyHelper.SelectStringValue(node2, _sortParameters[k].PropertyName, _namespaceManager);

                result = String.Compare(valueX, valueY, false, _culture);
                if (_sortParameters[k].Direction == ListSortDirection.Descending) 
                    result = -result;
 
                if (result != 0) 
                    break;
            } 

            return result;
        }
 
        private SortDescriptionCollection  _sortParameters;
        private XmlNamespaceManager  _namespaceManager; 
        CultureInfo _culture; 
    }
} 



// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK