Am I the only person that wants this? It seems to be something that could reasonably have been provided for any class with a public parameterless constructor. Now having to instantiate these properties inside the constructor of the class that uses them somewhat obviates the convenience of automatic properties.
A:
Indeed that might be useful, but it is what it is. There is no sign of this in C# 4.0, so you'll just have to use either a constructor or a field (and manual property implementation).
Re your "for any class with a public parameterless constructor" - actually, I'd assume that any implementation would be directly comparable to field initializers, so would work regardless of the constructor composition.
Marc Gravell
2009-04-15 11:06:32
@Marc, good point about the field initializers. However, my first concern was for types that only expose parametrized constructors: the compiler won't have values for parameters, just as it won't have values for field initializers.
ProfK
2009-04-15 11:12:27
+1
A:
I would want to be able to specify the degree of thread safety required. In particular, do you need locking code to be emitted?
John Saunders
2009-04-15 11:23:58
It's probably around this point that the MS team decided not to include this feature. :-)
ProfK
2009-04-15 11:58:42