Using List<T> with BusinessListBase

Using List<T> with BusinessListBase

Old forum URL: forums.lhotka.net/forums/t/1949.aspx


hunor posted on Monday, December 11, 2006

Csla provides wonderful base classess for business objects, sorting, filtering, but I could not find an easy way to implement Find(), FindAll(),ForEach(), RemoveAll()... basically all the methods, what the generic List<T> class implements.

My solutions is to create a new base class for my business objects inherited from BusinessBaseList :

public abstract class SolBusinessListBase<T, C> : BusinessListBase<T, C>
where T : BusinessListBase<T, C>
where C : SolBusinessBase<C>

In this class a define a "List" property: 

public List<C> List
{
get{ return (List<C>)this.Items; }
}

Now in my business objects I can use all the List<C> methods , like

List<Client> list = Clients.List.FindAll(delegate(Client client) { return client.LastName.StartsWith("A"); });

I do not have a deep knowledge about type casting, so I wonder how much is the overhead on the
    (List<C>) this.Items

Is this the right way to do this, or is there a better way ?

Any help would be appreciated.

Thanks

Hunor

 

 

 

Copyright (c) Marimer LLC