日期:2014-05-18 浏览次数:21508 次
public class OrderGoodInfo
    {
        private int _type;
        private int _goodid;
        private int _number;
        private string _name;
        private decimal _price;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
       
        public int Type
        {
            get { return _type; }
            set { _type = value; }
        }
        public int GoodId
        {
            get { return _goodid; }
            set { _goodid = value; }
        }
        public int Number
        {
            get { return _number; }
            set { _number = value; }
        }
        public decimal Price
        {
            get { return _price; }
            set { _price = value; }
        }
    }
#region 实体类,XML互操作
        /// <summary>
        /// 实体类序列化成xml
        /// </summary>
        /// <param name="enitities">The enitities.</param>
        /// <param name="headtag">The headtag.</param>
        /// <returns></returns>
        public static string ObjListToXml<T>(List<T> enitities, string headtag)
        {
            StringBuilder sb = new StringBuilder();
            PropertyInfo[] propinfos = null;
            sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            sb.AppendLine("<"+headtag+">");
            foreach (T obj in enitities)
            {
                //初始化propertyinfo
                if (propinfos == null)
                {
                    Type objtype = obj.GetType();
                    propinfos = objtype.GetProperties();
                }
                sb.AppendLine("<item>");
                foreach (PropertyInfo propinfo in propinfos)
                {
                    sb.Append("<");
                    sb.Append(propinfo.Name);
                    sb.Append(">");
                    sb.Append(propinfo.GetValue(obj, null));
                    sb.Append("</");
                    sb.Append(propinfo.Name);
                    sb.AppendLine(">");
                }
                sb.AppendLine("</item>");
            }
            sb.AppendLine("</" + headtag + ">");
            return sb.ToString();
        }
        /// <summary>
        /// 使用XML初始化实体类容器
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="typename">The typename.</param>
        /// <param name="xml&quo