Created
March 18, 2025 17:11
-
-
Save dontpaniclabsgists/5e80b7973dfd966a3853ef162397fd40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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