C
C#2y ago
FroH.LVT

✅ 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";
}
public class Sample{
public List<TestCategory> TestList {get;set;}
}

public class TestCategory{
public string Value {get;set;} = "Random string";
}
7 Replies
FroH.LVT
FroH.LVT2y ago
this is current result
FroH.LVT
FroH.LVT2y ago
But i want something like this:
FroH.LVT
FroH.LVT2y ago
It's my first time to do stuff with XML, quite new to this. What can I do to achieve my target? Thank you 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);
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
Pobiega2y ago
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.LVT
FroH.LVT2y ago
Yes, i'm trying to do that this is what I have to make
FroH.LVT
FroH.LVT2y ago
Stack Overflow
XML string array deserialize as different type name
I have the following C# class property: private List<string> _accountTypes; [XmlArray(ElementName = "accountTypes")] public List<string> AccountTypes { get { return _accountTypes;...
FroH.LVT
FroH.LVT2y ago
ah I found this !answer
Want results from more Discord servers?
Add your server
More Posts