LLBLGen Pro version + buildnr = Version 2.0.0.0 Final (November 6th, 2006)
Template = Adapter
.NET version = 2.0
I'm trying to port some code that another programmer wrote using LLBLGen 1.x to LLBLGen 2.0
It appears to be a routine for sorting collections of entities.
public static void Sort(IEntityCollection2 collection, IComparer comparer, bool reverse)
{
EntityCollection
ArrayList tempArray = new ArrayList();
tempArray.AddRange((IList) collection);
tempArray.Sort(comparer);
((EntityCollectionBase2)collection).Clear();
if (!reverse)
{
for (int i = 0; i < tempArray.Count; i++)
collection.Add((IEntity2) tempArray[i]);
}
else
{
for (int i = tempArray.Count - 1; i >= 0; i--)
collection.Add((IEntity2) tempArray[i]);
}
}
This code will not compile when using LLBLGen Version 2.0.
I get this error:
Using the generic type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2<TEntity>' requires '1' type arguments
for this line:
((EntityCollectionBase2)collection).Clear();
It appears that EntityCollectionBase2 is now a generic collection while in version 1.x it wasn't.
So I was wondering how I should rewrite the method so it compiles in version 2.x.
I notice there is a class called EntityCollectionNonGeneric, but I'd prefer to use generics.
So I changed the line to what I think would retain the behavior of the method. As a relative newbie, I guess I'm just looking for confirmation.
((EntityCollectionBase2<EntityBase2>)collection).Clear();
I have some questions about this code too.
Looking at the documentation it says that IEntityCollection2 is the Interface for the EntityCollection2 type. But I don't see the EntityCollection2 type anywhere in the documentation. Is that a mistake in the documentation? Is it really supposed to say EntityCollectionBase2?
Why does he cast collection to EntityCollectionBase2? Couldn't he just call Clear() without it since it is one of the methods specified in the IEntityCollection2 interface?
Why does he pass in IEntityCollection2 instead of EntityCollectionBase2? Is that just good programming practice? I don't think we would ever be making another collection class that implements IEntityCollection2.