protected override IEnumerable<BsonFieldDetail> OnBeforeFinishBsonRender(IEnumerable<BsonFieldDetail> fields)
{
//convert to a list that can be modified
List<BsonFieldDetail> list = fields.ToList();
//get all of the ids to use
IEnumerable<BsonFieldDetail> ids = fields.Where(item => item.Type is MongoOidType);
list.RemoveAll(item => item.Type is MongoOidType);
list = list.OrderBy(item => item.Length).ToList();
//because the items are shared in the same list
//we have to insert these one at the time since
//if we use AddRange an exception will be thrown
//since the list is modified while enumerating
//through the values. We're also going backwards
//to make sure they retain their original order
for (int index = ids.Count(); index-- > 0; ) {
list.Insert(0, ids.ElementAt(index));
}
//then return the list
return list.AsEnumerable();
}