读书人

如何序列化部分属性

发布时间: 2012-03-24 14:00:46 作者: rapoo

怎么序列化部分属性
问题描述:
实体有很多属性,第一个方法序列化其中一个属性,第二个方法序列化另一个属性。。。。,一个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

读书人网 >Web Service

热点推荐