I am serializing an object into XML.
consider class
public class EmpInfo
{
public string Code;
public string FirstName;
public string LastName;
public string Designation;
public int Salary;
}
If I don't provide salary then it is by default set as 0 I don't want default values to be set.
In case of Designation, if I don't provide then value is automatically NULL. That tag is not included in XML.
How should I omit the Salary tag if Salary is not provided?
public int? Salary;
– I4V Jul 18 '13 at 13:26int Salary
be ignored in the XML always and have astring SalarySerialized
wrapper which does conversion. If the value is0
it returnsnull
, any other number it returns the string representation. EDIT: Oh fine l4V, give a better suggestion why don't you! – Chris Sinclair Jul 18 '13 at 13:26null
; it outputs an element "<Salary xsi:nil="true" />" – Chris Sinclair Jul 18 '13 at 13:29