DCSIMG
Quick Tip – Using the ShouldSerializeXXX methods - Gil Fink's Blog

Gil Fink's Blog

Fink about IT

News

Microsoft MVP

My Facebook Profile My Twitter Profile My Linkedin Profile

Locations of visitors to this page

Creative Commons License

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2013 Gil Fink

Hebrew Articles

Index Pages

My OSS Projects

English Articles

Quick Tip – Using the ShouldSerializeXXX methods

Quick Tip – Using the ShouldSerializeXXX methods

Something that I Quick Tip – Using the ShouldSerializeXXX methods
encountered last week.
The ShouldSerialize methods
are optional methods that
you can provide for
a class property.
These methods are built as ShouldSerializePropertyName
and inside of them you can provide a check that will determine whether the
property should be serialized or not. Of course this can be achieved only in
serializable classes.
An example of use:

public string Text { get; set; }
 
public bool ShouldSerializeText()
{
    return string.IsNullOrEmpty(Text);
}

Very helpful if I don’t what to serialize data that is not available.
For further reading - ShouldSerialize and Reset Methods.
Enjoy!

DotNetKicks Image

Comments

Reflective Perspective - Chris Alcock » The Morning Brew #425 said:

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #425

# September 3, 2009 10:19 AM