List.ForEach Method

List.ForEach Method

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


csla_rocks1 posted on Thursday, July 26, 2007

In the current Business List Base architechure List.ForEach Method is not exposed.
(  http://msdn2.microsoft.com/en-us/library/bwabdf9z.aspx )

If you have a BO say PersonList it would very useful to write something like

List<person> young = people.FindAll(delegate(Person p) { return p.age < 25; });
Console.WriteLine("Age
is less than 25")

OR

// Sort by name
Console.WriteLine("Sorted list, by name");
people.Sort(
delegate(Person p1, Person p2)
   {
return p1.name.CompareTo(p2.name); });

people.ForEach(delegate(Person p)
   { Console.WriteLine(String.Format("{0} {1}", p.age, p.name)); });

How can we achieve this with businesslist base.

Thanks




triplea replied on Thursday, July 26, 2007

It appears you want to sort a list for presenting it in the UI. Why not just use the SortedBindingList object to do all the above for you?

csla_rocks1 replied on Thursday, July 26, 2007

Triplea
Thanks for such a quick reply . Actually there are numerous times in business logic where I need to loop through the list to find something or find group of objects.
The findall or foreach methods can used to quickly find these things.

Is there a reason  why Rocky did not expose these with businesslistbase?

triplea replied on Thursday, July 26, 2007

Sorry I am not sure if that was done intentionally or if it was overlooked. In any case if you extend Businessbase and the other base classes you can always add this functionality with internal or public methods so that might be a solution...

Curelom replied on Thursday, July 26, 2007

I might be wrong on this, but I believe the .ForEach option uses predicates and business objects don't support predicates.  They were on the wish list for quite some time.  If you take a look at the current wish list/roadmap, you will see that this request has been removed in favor of using Linq in .net 3.5.

csla_rocks1 replied on Thursday, July 26, 2007

Rocky
Can you please shed some light on this and enlighten us :)
Thanks

Copyright (c) Marimer LLC