views:

110

answers:

1

Hello,

This is something I find rather curious, that a lot of third party libraries such as FileHelpers and Command Line Parser are designed to work at field level rather than property level. Is there a particular reason why so many have chosen to target their tools at public fields rather than properties?

My personal feeling is that properties expresses class design better than public fields and as such whenever I need to expose a field as public I always use a property.

+2  A: 

An interesting question. In my fevered opinion, with a few exceptions (*), most APIs should target properties (for all the usual reasons) unless the developer gives indication (for example, by marking a field with an attribute). So I largely agree. Indeed, there is very little performance issue.

The biggest reason I can think of (from experience) is that read-only properties are a pain; maybe that is what they are thinking of? But that is a poor excuse.


*=the exception being things like BinaryFormatter which by definition is (by default) a state serializer. And I'm not a fan of that ;-p

Marc Gravell
that's an interesting point, hadn't thought about read-only properties
theburningmonk