/// <summary> /// 访问xml中对象集合 /// </summary> /// <param name="xml"></param> /// <returns></returns> private T VisitXmlGeneric(string xml) { T collection = Activator.CreateInstance <T>(); List <string> xmlArr = XmlTagHelper.GetTagContents(xml, _rootTag, "", _needCData); foreach (var itemXml in xmlArr) { AddElement(collection, itemXml, obj => { Add(collection, obj); }); } return(collection); }
/// <summary> /// 访问xml中对象集合 /// </summary> /// <param name="xml"></param> /// <returns></returns> private T VisitXmlArray(string xml) { List <string> xmlArr = XmlTagHelper.GetTagContents(xml, _rootTag, "", _needCData); Array array = Array.CreateInstance(_elementType, xmlArr.Count); T collection = (T)Convert.ChangeType(array, typeof(T)); int index = 0; foreach (var itemXml in xmlArr) { AddElement(collection, itemXml, obj => { SetValue(collection, obj, index++); }); } return(collection); }