• Elegant Code Cast


    View in iTunes Any Podcatcher

How have the new features of C# changed your code?

Here is a simplified example of how the functional programming style of Linq has impacted the way I would do a DDD service implementation.

Before:

IEnumerable<TDomainEntity> domainEntities = Repository.Find(criteria);
IEnumerable<TDto> dtos = Assembler.DomainToService(domainEntities);
return new List<TDto>(dtos);
After:
return Repository
           .Find(criteria)
           .ToList()
           .ConvertAll<TDto>(Assembler.DomainToService);
Thoughts? Samples? WTF’s?
kick it on DotNetKicks.com

2 Responses to “How have the new features of C# changed your code?”

  1. return Repository.Find(criteria).Select(Assembler.DomainToService).ToList();

    Even easier ;)

  2. Ah yes, very nice!

Leave a Reply

Close
E-mail It