c# object to xml
来源:互联网 发布:淘宝卖雅尼的cd 编辑:程序博客网 时间:2024/04/27 21:08
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml;using System.Xml.Serialization;namespace object2xml{ public static class XmlExtension { public static string Serialize<T>(this T value) { if (value == null) return string.Empty; var xmlserializer = new XmlSerializer(typeof(T)); using (StringWriter stringWriter = new StringWriter()) { using (var writer = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true })) { xmlserializer.Serialize(writer, value); return stringWriter.ToString(); } } } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace object2xml{ public class Persion { public string Name { get; set; public int Age { get; set; } }}
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml;using System.Xml.Serialization;namespace object2xml{ class Program { static void Main(string[] args) { Persion p = new Persion(); p.Name = "张三"; p.Age = 18; var xml = p.Serialize<Persion>(); Console.WriteLine(xml); } }}
0 0
- c# object to xml
- Serialization from an Object to XML Document in C#
- object to xml
- c# json to object
- C#操作XML报Object reference not set to an instance of an object
- XmlSerializer to XML and XML to object
- Document Object To XML String
- c# XML to Excel
- C# LINQ to XML
- C# LINQ to XML
- C# LINQ to XML
- c# Linq to Xml
- C# LINQ to XML
- Convert object to json and json to object in C#
- xml-to-object转换(Digester用法)
- Convert Xml to json object in android
- C# 3.0 LINQ to XML
- C#中的Linq to Xml
- [LeetCode]Valid Palindrome
- 天声人語 20150521
- Mac下挂载EFI分区
- wget命令
- 由MD5引发的血案
- c# object to xml
- Android笔记之判断ListView滑动到顶部或底部
- 封装格式化java数据发往C++ socket 项目记录
- 这个简笔画很值得学,哄小孩必备
- 网易新闻iOS版 使用过的第三方开源类库
- EasyFogofWar 简单战争迷雾系统 unity3d插件 使用教程
- IOS_改变UITextField placeHolder颜色、字体
- Move.h && Move.c
- Map----映射