C# xml文件反序列化读入数据到object
public static object DeSerializeFromXmlString(System.Type typeToDeserialize, string xmlString) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xmlString); MemoryStream memoryStream = new MemoryStream(bytes); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeToDeserialize); return xmlSerializer.Deserialize(memoryStream); } Example [Test] public void GetBigList() { var textRepository = ObjectFactory.GetInstance<ITextRepository>(); List<BrandAndCode> brandAndCodeList = textRepository.GetList(...); string xml = SerializeToXmlString(brandAndCodeList); Console.Out.WriteLine("xml = {0}", xml); var brandAndCodeList2 = DeSerializeFromXmlString(typeof (BrandAndCode[]), xml); }