专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Web Service

如何序列化部分属性

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
怎么序列化部分属性
问题描述:
实体有很多属性,第一个方法序列化其中一个属性,第二个方法序列化另一个属性。。。。,一个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
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: