C#model序列化xml

 private string Serialier<T>(T model)
        {
            using (StringWriter streamWriter = new StringWriter())
            {
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("", "");
                XmlSerializer xmlSerializer = new XmlSerializer(model.GetType());
                xmlSerializer.Serialize(streamWriter, model,ns);
                return streamWriter.ToString();
            }
        }

参数model是数据模型

posted @ 2019-11-24 19:50  王小鹏  阅读(477)  评论(0编辑  收藏  举报