Dto fields vs. properties

 
50   50
Sep 14, 2011
 
Noticed that in the Service layer message classes you use fields but in DTOs you use properties. Any reason why?



50   50
Jan 11, 2012
DTO's use properties because DTO's need serialize and de-serialize. Fields are not able to. Therefore your DTO needs to be marked as serializable.

50   50
Jan 11, 2012
The messages are serializable too but all of them have fields. Correct if I'm wrong.

50   50
Jan 11, 2012
Yes, a very valid point. After some reflection I can now see that fields and properties are able to be serialized. I guess the only other reason to use properties is because properties are bindable and fields (variables) are not. Added to that if you use reflection to reference these things then I think the behaviour is slightly different.

I always thought that fields were not serializable.... I now know they are so that is good!