Power5: Custom anonymous types

[This post is part of a series, "wish-list for future versions of VB"]

 

IDEA: Custom anonymous types. We should allow the user to provide a custom "anonymous type" template. This idea came from Bill McCarthy, who gave two examples:

        Dim customer = New With {.FirstName="Fred", .LastName="Flintstone"} From MyTemplate

        Dim projection = From c In Customers

                         Where c.LastName="Flintstone"

                         Select New With {c.LastName, c.FirstName} From MyTemplate

 

Provisional evaluation from VB team: We think this idea has limited use. Anonymous types will only ever appear inside method bodies and so there's not much use for them to have special behavior. It'd also incur a very heavy new-syntax cost, to be able to write a "MyTemplate" which is general enough to support whatever properties the user wants to put in there.

There are probably better IDE solutions. For instance, you could select an anonymous-type expression, right-click, "Generate named type" from it, and replace all matching anonymous types in your code that have the right shape with this new named type.