ShouldSerialize*

To remove empty value from serialized object you just need to create a method called ShouldSerializeX where X is the name of the property to check.

    public class Context
    {
        [XmlAttribute]
        public string ReturnCode { get; set; }

        public bool ShouldSerializeReturnCode()
        {
            return !String.IsNullOrEmpty(ReturnCode);
        }
    }