Properties vs Fields

Topics: General Discussion, Sandcastle
Dec 13, 2007 at 1:04 PM
If I want a public read/write property in a class I write

public string MyProperty

C# infers the get/set accessors from this.

I only explicitly write the accessors if I want the property to be read- or write-only...

public string MyProperty {
get { return _MyProperty; }
}

Now, when I generate the help for a class the read/write properties are (a) referred to as fields and (b) don't appear on either of the "allmembers" or "properties" pages of the class.

This strikes me as a short coming of either SandCastle or DocProject (I imagine it's the former).

--
Stuart
Coordinator
Dec 13, 2007 at 8:04 PM
Hi Stuart,

You're referring to a language feature of C# 3.0. Are you using DocProject 2008 Beta 2?

Regardless, it sounds to me like a bug in Sandcastle since MRefBuilder.exe (a program that ships with Sandcastle) is responsible for reflecting into assemblies.

You may want to report this in the MSDN forums or email Anand.

- Dave
Coordinator
Dec 14, 2007 at 3:51 AM
Hi Stuart,

Taking another look at your example code, it seems that the syntax you're using actually describes a field, not a property, in all versions of C#. To use automatic properties in C# 3.0 you must use the following syntax:

public string MyAutoProperty { get; set; }
I haven't tried this myself so I don't know if it will be handled by Sandcastle correctly, but I assume that it will :)

- Dave
Dec 14, 2007 at 6:21 AM

Taking another look at your example code, it seems that the syntax you're using actually describes a field, not a property,

Really? How about that? Everyday's a school day, isn't it?