首页 > 代码库 > .NET XmlHelper帮助类
.NET XmlHelper帮助类
public class Program { static void Main(string[] args) { Student stu1 = new Student() { Name = "okbase", Age = 10 }; string xml = XmlHelper.Serializer(typeof(Student), stu1); Console.Write(xml); Student stu2 = XmlHelper.Deserialize(typeof(Student), xml) as Student; Console.Write(string.Format("名字:{0},年龄:{1}", stu2.Name, stu2.Age)); Console.ReadKey(); } public class Student { public string Name { set; get; } public int Age { set; get; } } /// <summary> /// 将传入的字符串中间部分字符替换成特殊字符 /// </summary> /// <param name="value">需要替换的字符串</param> /// <param name="startLen">前保留长度</param> /// <param name="endLen">尾保留长度</param> /// <param name="replaceChar">特殊字符</param> /// <returns>被特殊字符替换的字符串</returns> private static string ReplaceWithSpecialChar(string value, int startLen = 4, int endLen = 4, char specialChar = ‘*‘) { try { int lenth = value.Length - startLen - endLen; string replaceStr = value.Substring(startLen, lenth); string specialStr = string.Empty; for (int i = 0; i < replaceStr.Length; i++) { specialStr += specialChar; } value = http://www.mamicode.com/value.Replace(replaceStr, specialStr);>
使用方法
public class Program { static void Main(string[] args) { Student stu1 = new Student() { Name = "okbase", Age = 10 }; string xml = XmlHelper.Serializer(typeof(Student), stu1); Console.Write(xml); Student stu2 = XmlHelper.Deserialize(typeof(Student), xml) as Student; Console.Write(string.Format("名字:{0},年龄:{1}", stu2.Name, stu2.Age)); Console.ReadKey(); } public class Student { public string Name { set; get; } public int Age { set; get; } } }
.NET XmlHelper帮助类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。