✅ Configure Xml Serialization

Hey folks! I have a type like this:
class DateTimeWrapper
{
    public DateTime Value;
}

I'm serializing this via System.Xml. I would like to have this type serialize as if I were serializing the wrapped Value, rather than the whole type.

In other words, I want it to serialize as this:
2023-08-04 00:00:00
rather than
<Value>
    2023-08-04 00:00:00
</Value>

What are my options to make this happen? I would ideally like to avoid changing the serializer itself, but rather use an approach that the serializer will respect. For example, newtonsoft json uses JsonConverter, but I'm not sure if System.Xml has a similar concept.
Was this page helpful?