hi,
you have a collection of what ? File has all its methods static so you
cannot use it.
FileInfo maybe? I will assume it.
I did a while ago a class to compare any kind of class, it was my first real
reflection code IIRC
It;'s very simple of use all you have to do is pass to the constructor the
name of the property and the ordering you want ( descending or ascending )
like:
new ClassSorter( "ListWriteTime", SortDirection.Ascending );
you could also use a property of the property:
new ClassSorter( "ListWriteTime.Hour", SortDirection.Ascending );
Hope this help, let me know if you need help with the code
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
*******************************************************
public class ClassSorter: IComparer
{
protected string sortBy;
protected SortByType sortByType;
protected SortDirection sortDirection;
#region Constructors
public ClassSorter(string sortBy, SortByType sortByType, SortDirection
sortDirection)
{
this.sortBy = sortBy;
this.sortByType = sortByType;
this.sortDirection = sortDirection;
}
#endregion
int Compare( object x, object y, string comparer)
{
if ( comparer.IndexOf( ".") != -1 )
{
//split the string
string[] parts = comparer.Split( new char[]{ '.'} );
return Compare( x.GetType().GetProperty( parts[0]).GetValue(x, null) ,
y.GetType().GetProperty( parts[0]).GetValue(y, null) , parts[1]
);
}
else
{
IComparable icx, icy;
icx =
(IComparable)x.GetType().GetProperty( comparer).GetValue(x, null);
icy =
(IComparable)y.GetType().GetProperty( comparer).GetValue(y, null);
if ( x.GetType().GetProperty(comparer).PropertyType ==
typeof(System.String) )
{
icx = (IComparable) icx.ToString().ToUpper();
icy = (IComparable) icy.ToString().ToUpper();
}
if(this.sortDirection == SortDirection.Descending)
return icy.CompareTo(icx);
else
return icx.CompareTo(icy);
}
}
public int Compare(object x, object y)
{
return Compare( x, y, sortBy);
}
}
public enum SortByType
{
Method = 0,
Property = 1
}
public enum SortDirection
{
Ascending = 0,
Descending = 1
}
*******************************************************