Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xml Serialization Support #59

Open
dgg opened this issue Dec 29, 2023 · 0 comments
Open

Xml Serialization Support #59

dgg opened this issue Dec 29, 2023 · 0 comments
Assignees
Milestone

Comments

@dgg
Copy link
Owner

dgg commented Dec 29, 2023

Since serialization support has been dropped in version 7 some help needs to be provided.
For XML serialization a record XmlSerializableMoney will be provided for use in DTOs. It will be convertible to and from Money and will provide facilities to either create or modify XmlAttributeOverrides to pass to a XmlSerializer instance to reshape how the XmlSerializableMoney is XML serialized.

public readonly record struct SerializableMoney(decimal Amount, CurrencyIsoCode Currency);

public record MoneyContainerDto([property: XmlAttribute(attributeName: "da_name")]string Name, [property: XmlElement(ElementName =  "da_money")]SerializableMoney Money)
{
	public MoneyContainerDto() : this(string.Empty, new SerializableMoney()) { }
}

var overrides = new XmlAttributeOverrides();
		
overrides.Add(typeof(SerializableMoney), new XmlAttributes
{
	Xmlns = false,
	XmlRoot = new XmlRootAttribute("money")
});
overrides.Add(typeof(SerializableMoney), "Currency", new XmlAttributes
{
	XmlElements = { new XmlElementAttribute("currency") }
});
overrides.Add(typeof(SerializableMoney), "Amount", new XmlAttributes
{
	XmlElements = { new XmlElementAttribute("amount") }
});
XmlSerializer mcs = new XmlSerializer(typeof(MoneyContainerDto), overrides);
@dgg dgg added this to the Serialization milestone Dec 29, 2023
@dgg dgg self-assigned this Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant