[CSHARP-211] BsonClassSerializer should look for ShouldSerializeXyz methods and use them Created: 22/Apr/11  Updated: 02/Apr/15  Resolved: 03/May/11

Status: Closed
Project: C# Driver
Component/s: Feature Request
Affects Version/s: 1.0
Fix Version/s: 1.1

Type: New Feature Priority: Minor - P4
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

These methods would allow the decision whether a particular property should be serialized to be made at runtime. This is similar to [BsonIgnoreIfNull] but allows the developer to use custom criteria to decide whether to serialize the property or not. For example:

public class Employee {
// other fields
public string Zip;

public bool ShouldSerializeZip(string value)

{ return value != null && value != "' && value != "00000"; }

}



 Comments   
Comment by Robert Stam [ 03/May/11 ]

Done. Thanks to Saleem Brahmanapalli for contributing the implementation of this feature.

Comment by Robert Stam [ 28/Apr/11 ]

I've been looking for documentation on the SouldSerializeXyz methods in the XmlSerializer documentation, but haven't found any.

However, a test proves that the XmlSerializer definitely supports this:

http://www.pastie.org/1844886

Another background task has been to support classes that have been designed to be serialized with the XmlSerializer. Perhaps this JIRA should be replaced by a more encompassing one to support XmlSerialization in general.

Generated at Wed Feb 07 21:36:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.