C# 3.0 Automatic Properties
Posted on May 16th, 2007 in .Net, C#, EN |
Yesterday I read two excellent posts about C# 3.0 automatic properties feature: ScottGu’s «New C# “Orcas” Language Features: Automatic Properties, Object Initializers, and Collection Initializers» and Bart De Smet’s «C# 3.0 Automatic Properties explained».
It was a pleasure to see that my old «A programming language pattern idea» hit straight to the point.
By the way, this “Orcas” feature is still missing the “container” concept, enabling an access to the auto-generated field from the constructor. Another missing point is a read-only automatic properties.







6 Responses
Hear, hear. I second the “missing read-only automatic properties”. Especially with anonymous classes created with LINQ via projection, the option to create those properties as read-only would be so useful.
Maybe something like ‘new readonly { foo = “bar” };’
Creating a writable anonymous class via projection at best leaves the impression that setting those values means something. In reality it is very likely just a way to give you data to look at. It certainly doesn’t propagate the changes back to the originating object.
I thought about making an anonymous classes derived from LINQ queries to be immutable.
But I see that there is nothing to complain about this: Sree just blogged that they decided to infer all anonymous classes as immutable.
I did a first pass at implementing auto-properties in Mono: http://lists.ximian.com/pipermail/mono-devel-list/2007-May/023460.html
I’ll be redoing this patch soon(ish). Should be done by the end of the week.
Hi Scott!
Good to hear about it, especially since I somehow missed your post on this.
It’s in: http://groups.google.com/group/mono-svn-patches/browse_thread/thread/b103dbe0daa8532f/b148ce3221d099cb?lnk=gst&q=Scott+Peterson&rnum=1#b148ce3221d099cb
I mean, http://groups.google.com/group/mono-svn-patches/browse_thread/thread/288d3fddaca3c3d0/3dde563d5a948663?lnk=gst&q=Scott+Peterson&rnum=2#3dde563d5a948663