簡體   English   中英

列表 c# 的自定義(?)序列化

[英]custom(?) serialization of list c#

我正在嘗試將包含列表的 c# object 轉換為 XML。 該列表很好,如下所示:

<image>dummy</image>
<image>dummy2</image>
<image>dummy3</image>

等等。 我希望標簽是獨一無二的,例如:

<image_1>dummy</image_1>
<image_2>dummy2</image_2>
<image_3>dummy3</image_3>

但我不太確定如何得到這個結果。

任何輸入表示贊賞:)

解決方案的粗略草圖:

Stream stream = ... // your output stream

XmlWriter xml = new XmlWriter(stream)

xml.WriteStartDocument();

int index = 0;
foreach (var x in list) {
  xml.WriteStringElement("index_" + index++, x.ToString());
}

xml.Close();

https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter?view=netcore-3.1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM