Code: C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
namespace WindowsApplication3.Data
{
public class LogEntryCollection : ObjectCollection<LogEntry>
{
private DataObject owner;
public DataObject Owner
{
get { return this.owner; }
}
protected override void InsertItem(int index, LogEntry item)
{
LogEntry le = new LogEntry(this.owner);
le.Text = item.Text;
le.Time = item.Time;
item = le;
base.InsertItem(index, item);
}
public void Persist()
{
DataManager.Current.Engine.PersistChanges(this);
}
public LogEntryCollection(DataObject owner)
{
this.owner = owner;
}
public LogEntry[] Sort()
{
LogEntry[] coll = new LogEntry[this.Count];
this.CopyTo(coll, 0);
for (int i = 0; i < coll.Length - 1; i++)
{
for (int j = 0; j < coll.Length - 1 - i; j++)
{
if (coll[j + 1].Time.CompareTo(coll[j].Time) > 0)
{
Swap(ref coll[j], ref coll[j + 1]);
}
}
}
return coll;
}
private static void Swap(ref LogEntry le1, ref LogEntry le2)
{
LogEntry tmp = le2;
le2 = le1;
le1 = tmp;
}
}
}

