2 yidaimu yidaimu 于 2016.03.08 18:32 提问

XmlSerializer序列化时是不是不能加注释

public class Rule
{

public string device;
public int channel;
}
//序列化List
private void Serialize(List list)
{
XmlDocument xd = new XmlDocument();
using (StringWriter sw = new StringWriter())
{
try
{
XmlSerializer xz = new XmlSerializer(list.GetType());
xz.Serialize(sw, list);

xd.LoadXml(sw.ToString());

xd.Save("a.xml");
}
catch (Exception ex)
{
MessageBox.Show("序列化时发生错误:" + ex.Message);
}

        }
    }
            如果不使用XmlDocument去修改XML,那怎么才能让XmlSerializer生成的xml中包含对device和channel节点的注释?
            先谢谢各位了。

1个回答

hnxcjsbzzysljf
hnxcjsbzzysljf   2016.10.08 01:32

er序列化时是不是不能加注释
xml注释xmlserializer
public class Rule
{

public string device;
public int channel;
}
//序列化List
private void Serialize(List list)
{
XmlDocument xd = new XmlDocument();
using (StringWriter sw = new StringWriter())
{
try
{
XmlSerializer xz = new XmlSerializer(list.GetType());
xz.Serialize(sw, list);

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!