Monday, 16 February 2009

Brisanje zapisov [CSLA]

Remove,Contains, and ContainsDeleted
Collections that inherit from BusinessListBase automatically have Remove(), Contains(), and
ContainsDeleted() methods. Each of these accepts a reference to a child object as a parameter, and
often that is sufficient.
For this collection, however, it turns out that the UI code in Chapters 9 and 10 is much simpler
if it is possible to remove or check for a child object based on a resource Id property value rather
than a child object reference. To provide this capability, each of these three methods is overloaded
with a different implementation. For instance, here’s the Remove() method:
public void Remove(int resourceId)
{
foreach (ProjectResource res in this)
{
if (res.ResourceId == resourceId)
{
Remove(res);
break;
}
}
}

This method accepts the resourceId value as a parameter, and that value is used to locate the child
object (if any) in the collection. The Contains() and ContainsDeleted() overloads follow the same basic
approach.
Not all collections will need overloads of this type, but such overloads are often useful to simplify
the use of the collection and reduce code in the UI.

0 comments:

Post a Comment