Expert Texture Home Contact me About Subscribe Digipede Connect on LinkedIn rwandering on Twitter rwandering on FriendFeed

The blogged wandering of Robert W. Anderson

Automatic Properties Follow-up

Back in March, I posted Automatic Properties in C# 3.0 which included a couple of questions.  At the time I hadn’t installed any Orcas beta.  My post was based on other posts (including one from Bart DeSmet’s excellent blog: C# 3.0 Automatic Properties Explained).  My questions leapt out at me (maybe I’ll post about why that is . . .). Since that post, I have played a bit with the VS 2008 betas as well as built and tested the Digipede SDK samples.

A recent comment reminded me that I should revisit the questions.

Question 1: Is there an attribute to set the automatic field name?

Reason?  To maintain binary-serialization compatibility when moving from automatic properties to “normal” properties. 

Answer:  I don’t know if there is explicitly.  The underlying field name seems to have been changed since Bart’s first post and VS 2008 beta 2 (they have improved it so the field name can be derived from the property name).  This is good, because it might mean that the automatic property could be converted to the “normal” kind of property while maintaining default binary serialization; however, the backing field name looks like:


. . . and angle brackets are not valid for member names — the compiler can generate them, but aren’t valid C# syntax.  So, this is not quite what I want.

Question 2: Is there an attribute you can put on the automatic property to hide the underlying field or is it automatic?

Reason?  By default, properties with backing fields result in (usually) duplicated information in the debugging views.  If the backing field is generated by the compiler, it would make sense to just hide it (with the DebuggerBrowsableAttribute or some other way).

Answer:  This is automatic.  Good.  Probably a result of the CompilerGeneratedAttribute that is added to the generated backing field.


Based on what I know now, I wouldn’t use automatic properties if default binary serialization is likely to be used.  Regardless of this possibly arcane issue, automatic properties are cool.  I like them.

Tags: , , , ,


No comments yet »

Your comment

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>