I use nullable value types a lot when designing classes that have properties which may remain null, i.e. when the object is being persisted. For example:
public int? MyProperty { get; set; }
My question is: should all value-type properties in public (API) POCOs be nullable because it's not known when the consumer will set the values, even in cases where the properties must not be null when the POCO is saved? If not, then there's the risk that the "default" value (e.g. 0
for an int
) will accidentally be saved.
Aucun commentaire:
Enregistrer un commentaire