I have an private List and I want to expose the ability to query the List and return a new List with new cloned items. I can pass in delegates for filtering and sorting, which works fine, but being able to use Linq expressions would be much more elegant.
I've added an simplified example of what I'm trying to do, which might help as I don't think I've explained what I want to do very well.
public class Repository
{
private List<SomeModel> _models;
private object _lock;
public List<SomeModel> GetModels(Func<SomeModel, bool> predicate)
{
List<SomeModel> models;
lock (_lock)
{
models = _models.Where(m => predicate(m))
.Select(m => new SomeModel(m))
.ToList();
}
return models;
}
}