Something like this:
public string GetList(IEnumerable<TaskRelation> relations,
int taskId, int relTypeId,
Func<TaskRelation, string> projection)
{
var query = relations.Where(r => r.TaskId == taskId &&
r.RelTypeID == relTypeId)
.Select(projection));
.ToArray()
return string.Join("; ", query.ToArray());
}
Then use it like this:
string zones = GetList(reslations, taskID, 14, r => r.RefZone.shortdesc);
Note that I've assumed LINQ to Objects - if this is LINQ to SQL (or something similar) then you should specify IQueryable<TaskRelation>
and Expression<Func<TaskRelation, string>>
so that the filtering and projecting can be done at the data source.
Jon Skeet
2010-08-11 13:26:02