Immutable Object Graph updates

Andrew Arnott

In my last post, I introduced a T4 template that constructs efficient and quite capable immutable objects based on the simplest mutable type definition. I also mentioned that the published sample is (necessarily, ala T4 style) open source and hosted online. Two outsiders have already submitted pull requests that have been accepted. Some thoughtful feedback came in the form of comments to my last blog post as well. Thank you for your participation!

The latest incarnation of the T4 template is substantially improved over what my last post described. Here are a few of them:

  1. The immutable types now look and feel more like the immutable collections, having static factory Create() methods instead of a static Default property.
  2. The With(…) multiple parameter method is easier to use.
  3. Partial methods give you the opportunity to set defaults for any property on your type.
  4. Certain fields can be marked as required, so that they are not optional parameters in the Create() method.
  5. Better support for immutable collections as members of the immutable types.
  6. The T4 template is broken up into several files, modeled as extensions, making it easier for you to add additional functionality to the template without having to fork the code in your own codebase, making future updates from the official project easier.
  7. Better support for a network of immutable objects referencing each other (the graph part of the name).

#7 is where I expect to spend much of the future work on this effort.

If this topic interests you, please take a fresh look at the latest version, and keep the feedback coming.

0 comments

Discussion is closed.

Feedback usabilla icon