Replies: 1 comment 1 reply
-
You will need an additional field for string format projection. Something like: using System;
using System.IO;
using System.Xml.Serialization;
XmlSerializer serializer = new(typeof(A));
string xmlString = @"
<A>
<Age>2023-01-01 12:00:00.111</Age>
</A>
";
using TextReader reader = new StringReader(xmlString);
if (serializer.Deserialize(reader) is A a)
{
Console.WriteLine("Parsed Age: {0}", a.AgeString);
}
else
{
Console.WriteLine("Deserialization failed!");
}
public class A
{
[XmlIgnore]
public DateTime Age { get; private set; }
[XmlElement(nameof(Age))]
public string AgeString
{
get => Age.ToString("yyyy-MM-dd HH:mm:ss.fff");
set => Age = DateTime.Parse(value);
}
} Output:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For example, is the following code possible?
serialized result
Beta Was this translation helpful? Give feedback.
All reactions