I suggest you ...

Better debugging of object initializer blocks

Object initializer blocks allow you to assign property values at construction despite the constructor not accepting the values to assign. This is useful for thread safety because the object is assigned a pre-built instance in an atomic operation. In addition is the only way to initialize an anonymous type. But debugging object initializers are cumbersome at best, impossible at worse. Take, for example, the following code (also attached as bitmap showing line numbers):
var book = new
{
Isbn = isbn,
Title = service.GetTitle(isbn),
Author = service.GetAuthor(isbn),
Edition = service.GetEdition(isbn),
PublicationDate = service.GetPublicationDte(isbn),
Copyright = service.GetCopyright(isbn),
Publisher = service.GetPublisher(isbn),
PageCount = service.GetPageCount(isbn),
Topics = service.GetTopics(isbn),
Binding = service.GetBinding(isbn),
ListPrice = service.GetListPrice(isbn),
AmazonReview = service.GetAmazonReview(isbn),
AuthorBio = service.GetAuthorBio(isbn),
Language = service.GetLanguage(isbn),
AverageAmazonReview = service.GetAverageAmazonReview(isbn),
};

If I have an exception at line 54, the stack trace actually details line 43. Also, I am unable to put breakpoints on individual lines within the block.

40 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Peter Ritchie shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base