C#
C#

help

Root Question Message

FroH
FroH2/1/2023
✅ XML Serialization

I want to customize XML serialization.
This is sample class
public class Sample{
   public List<TestCategory> TestList {get;set;}
}

public class TestCategory{
   public string Value {get;set;} = "Random string";
}
FroH
FroH2/1/2023
this is current result
FroH
FroH2/1/2023
But i want something like this:
FroH
FroH2/1/2023
It's my first time to do stuff with XML, quite new to this.
FroH
FroH2/1/2023
What can I do to achieve my target? Thank you
FroH
FroH2/1/2023
Here is serialization code :
            var item = new Sample();
            item.TestList = new List<Category>(){new TestCategory(),new TestCategory(),new TestCategory(),new TestCategory(),};
            string fileName = "";
            XmlSerializer x = new XmlSerializer(typeof(Sample));
            TextWriter writer = new StreamWriter(fileName);
            x.Serialize(writer, item);
Pobiega
Pobiega2/1/2023
The simplest way would be to have a model that more accurately reflects the desired XML structure. You could map your original data into this new structure before serialization or after deserialization.
FroH
FroH2/1/2023
Yes, i'm trying to do that
FroH
FroH2/1/2023
this is what I have to make
FroH
FroH2/1/2023
ah I found this
FroH
FroH2/1/2023
!answer
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy