using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace DTS.Common.Utilities
{
///
/// this is a class for doing natural string compares like in explorer (using the explorer function)
/// http://msdn.microsoft.com/en-us/library/bb759947%28VS.85%29.aspx
///
/// requires XP or greater
public class NaturalStringComparer : IComparer
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int StrCmpLogicalW(String x, String y);
///
/// do a natural string compare between two strings
///
/// left string to compare
/// right string to compare
/// -1 if natural order of x is less than y, +1 if x is after y, 0 if they are equal
public int Compare(string x, string y)
{
if (null == x) { return -1; }
if (null == y) { return 1; }
return StrCmpLogicalW(x, y);
}
public static int StaticCompare(string x, string y)
{
if (null == x) { return -1; }
if (null == y) { return 1; }
return StrCmpLogicalW(x, y);
}
}
}