Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Created March 18, 2025 17:11
Show Gist options
  • Save dontpaniclabsgists/5e80b7973dfd966a3853ef162397fd40 to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/5e80b7973dfd966a3853ef162397fd40 to your computer and use it in GitHub Desktop.
public class Person
{
[XmlElement(ElementName = "First")]
public string FirstName { get; set; }
[XmlElement(ElementName = "Last")]
public string LastName { get; set; }
public int Age { get; set; }
[XmlElement(IsNullable = true)]
public string Email { get; set; }
public PhoneNumber[] PhoneNumbers { get; set; }
public bool ShouldSerializeAge()
{
// Only serialize Age if 18 or older
return Age >= 18;
}
}
public class PhoneNumber
{
[XmlIgnore]
public string AreaCode { get; set; }
[XmlIgnore]
public string Number { get; set; }
[XmlText]
public string FormattedNumber
{
get { return $"{AreaCode}-{Number}"; }
set {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment