当前位置: 代码迷 >> Web Service >> 如何序列化部分属性
  详细解决方案

如何序列化部分属性

热度:238   发布时间:2016-05-02 02:59:31.0
怎么序列化部分属性
问题描述:
实体有很多属性,第一个方法序列化其中一个属性,第二个方法序列化另一个属性。。。。,一个webservice文件上能不能同时存在这些方法?怎么设计呢
序列化方法如下:
C# code
public string Serialize<BusinessObject>(List<BusinessObject> GenericList)        {            XmlDocument result = new XmlDocument();            XmlDeclaration del = result.CreateXmlDeclaration("1.0", "utf-8", null);            result.AppendChild(del);            result.LoadXml("<Records></Records>");            foreach (BusinessObject obj in GenericList)            {                XmlElement Item = result.CreateElement("Record");                if (obj != null)                {                    PropertyInfo[] properties = obj.GetType().GetProperties();                    foreach (PropertyInfo property in properties)                    {                        if (property.GetValue(obj, null) != null)                        {                            Item.SetAttribute(property.Name, property.GetValue(obj, null).ToString());                        }                    }                }                result.DocumentElement.AppendChild(Item);            }            return result.InnerXml;        }


------解决方案--------------------
WebService 需要你自己实现序列化吗?

对于实体类来说,加上[Serializable]特性就可以了。
------解决方案--------------------
http://blog.csdn.net/lazyleland/article/details/6665681
  相关解决方案