I wish to project a collection from one type (Something
) to another type (SomethingElse
). Yes, this is a very open-eneded question, but which of the two options below do you prefer?
Creating a new instance using new
:
var result = query.Select(something => new SomethingElse(something));
Using a factory:
var result = query.Select(something => SomethingElse.FromSomething(something));
When I think of a projection, I generally think of it as a conversion. Using new
gives me this idea that I'm creating new objects during a conversion, which doesn't feel right. Semantically, SomethingElse.FromSomething()
most definitely fits better. Although, the second option does require addition code to setup a factory, which could become unnecessarily compulsive.
var result = query.Select(SomethingElse.FromSomething);