Reputation: 4582
Referencing CovertAll.
It doesn't seem like there is a way, but I have a value that needs to be updated in each element of the list that is not part of the source list. I have many other places in this project using .ConvertAll
but in this one place I need to pass in an additional parameter and was hoping to keep it consistent using .ConvertAll
.
.i.e looking for something like this:
lstNewStoreFrontOrders.ConvertAll(Order.ConvertToOrderDto(storeFront.Id))
public static OrderHeaderImportDTO ConvertToOrderDto(Order storeFrontOrder, int storeFrontId)
{
var orderHeader = new OrderHeaderImportDTO() {
StatusId = ORDER_CREATED,
StoreFrontId = storeFrontId,
.....
}
Upvotes: 1
Views: 343
Reputation: 42320
Sure, just use a lambda expression which captures storeFront.Id
:
lstNewStoreFrontOrders.ConvertAll(order => Order.ConvertToOrderDto(order, storeFront.Id))
After all, orders.ConvertAll(Foo)
is more or less just shorthand for orders.ConvertAll(order => Foo(order))
.
Upvotes: 5