I have encountered a situation where I need to exclude a prefix from an element when I serialize the element if I am processing records for a specific year (2016). However, if I am processing records for the previous year (2015), this prefix should be included.
Example:
The 2015 IRS Schema defines the CountryNm
and ForeignProvinceNm
fields as irs:CountryNm
and irs:ForeignProvinceNm
as child elements of the ForeignAddressGrpType
element.
I have the following defined in a class Address
. When I serialize these properties, I get irs:CountryNm
and irs:ForeignProvinceNm
as expected.
// IRS_Namespace.commonNamespace uses the prefix 'irs'.
[XmlElement(Namespace = IRS_Namespace.commonNamespace)]
public string CountryNm
{
get { return _CountryName; }
set { _CountryName = value.Trim(); }
}
[XmlElement(Namespace = IRS_Namespace.commonNamespace)]
public string ForeignProvinceNm
{
get { return _ForeignProvinceName; }
set { _ForeignProvinceName = value.Trim(); }
}
If I am interpreting the change documentation for Tax Year 2016 correctly, the IRS updated their Schema definition and removed the prefix from these two fields.
Question:
How can I do that conditionally remove the prefix from these fields when processing TY2016 data vs. TY2015 data?
The IRS has given direction that states sending any TY2015 data must use the 2015 schema, while new records being sent for TY2016, must use the 2016 schema.
Will I need to maintain two (or more, over time) versions of the Address
class?