惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
有赞技术团队
有赞技术团队
H
Help Net Security
V
Visual Studio Blog
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements

博客园 - mahope

一个算法题解 在ASP.NET web 站点中使用log4net (1.2.9) 在.NET 中实现 AOP Q & A:Does ASP.NET support one-way Web Service operations? openwave:Malformed server response web 项目的 csproj 文件要有对应的.webinfo文件才能在vs里面打开 - mahope 软件需求规范(SRS)指南 写需求文档的一般原则 删除everyone对c:的 访问权限后,运行asp.net出现DirectoryNotFoundException未找到路径“C:\”的一部分 - mahope - 博客园 NHibernate Mapping文件中如何指定类的字节数组属性 NHibernate.ADOException : Unable to perform find 对于事件不能调用BeginInvoke,可改用另外一层包装 IBM面试题试解(关于50条狗、50个人、病狗) Einstein's Riddle 爱因斯坦出的智力题? Artificial intelligence: Solving problems for the real world 一些面向对象的设计法则 重构、分支语句、虚函数、抽象函数与多态--《重构:改善既有代码设计》之读书心得 NHibernate 执行内嵌类(Nested Class)查询 为内嵌类(Nested Class)配置NHibernate的O/R Mapping文件
解决Web Service中传递子类实例时,序列化的问题。
mahope · 2006-03-26 · via 博客园 - mahope

首先,无论如何传递一个子类的实例是无法解决问题的。
其次,好像没有什么现成的方法能直接从子类的实例中创造出父类的实例来。我曾经尝试返回base,但是失败了。
于是,迫不得已,我只有通过反射来将子类对象的数据传递到父类对象去。
代码如下:

public class DerivedType:WS.BaseType,System.ICloneable 
    
{
 
public WS.BaseType Clone()
        
{
            WS.BaseType result 
= new WSClient.WS.BaseType();
            PropertyInfo[] props 
= result.GetType().GetProperties();
            
foreach (PropertyInfo prop in props)
                prop.SetValue(result, prop.GetValue(
thisnull), null);

            
return result;
        }


        
object ICloneable.Clone()
        
{
            
return this.Clone();
        }

}