We've written a web service which uses a simple entity translator to map the values of DTO back on to "real" server side business objects. As part of this excercise. We have come across an "interesting" distinction between explicitly set null values and clients having not set a value.
The problem is essentially that we want to set a default value on the real business object if the client has not explicitly set a value, however using standard nullable types there is no way to tell if a client has explicitly meant "set this to null" or just not set it.
The solution here is obviously some sort of "flag".
Within a business object we can track the state of a field internally using private "IsDirty" flags set within the property setters, but a DTO only really specifies an Interface so this means exposing this data to the public. This leaves a number of implementation options. The language is C# (so statically typed) so...
- We could expose an "IsSet" flag on each property?
- We could expose each property as a class which has a .Value and .IsSet property? etc. etc.
How would you choose to expose these "flags" on the Data Contract? What would you here regard as best practice for this?
Any opinions on this would be greatly appreciated.